update credits
[LibreOffice.git] / xmloff / source / text / XMLTextFrameContext.cxx
blob745ff637206fc077ce4a763e188942cdacaa4017
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/debug.hxx>
21 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/text/TextContentAnchorType.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/text/XTextFrame.hpp>
25 #include <com/sun/star/container/XNamed.hpp>
26 #include <com/sun/star/text/SizeType.hpp>
27 #include <com/sun/star/drawing/XShape.hpp>
28 #include <com/sun/star/document/XEventsSupplier.hpp>
29 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
30 #include <com/sun/star/io/XOutputStream.hpp>
31 #include <com/sun/star/text/HoriOrientation.hpp>
32 #include <com/sun/star/text/VertOrientation.hpp>
33 #include <sax/tools/converter.hxx>
34 #include <xmloff/xmlimp.hxx>
35 #include <xmloff/xmltoken.hxx>
36 #include "xmloff/xmlnmspe.hxx"
37 #include <xmloff/nmspmap.hxx>
38 #include <xmloff/xmluconv.hxx>
39 #include "XMLAnchorTypePropHdl.hxx"
40 #include "XMLEmbeddedObjectImportContext.hxx"
41 #include <xmloff/XMLBase64ImportContext.hxx>
42 #include "XMLReplacementImageContext.hxx"
43 #include <xmloff/prstylei.hxx>
44 #include "xmloff/i18nmap.hxx"
45 #include "xexptran.hxx"
46 #include <xmloff/shapeimport.hxx>
47 #include <xmloff/XMLEventsImportContext.hxx>
48 #include "XMLImageMapContext.hxx"
49 #include "XMLTextFrameContext.hxx"
51 #include "XMLTextListBlockContext.hxx"
52 #include "XMLTextListItemContext.hxx"
53 #include <xmloff/attrlist.hxx>
54 #include <comphelper/stl_types.hxx>
56 #include <map>
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::text;
63 using namespace ::com::sun::star::xml::sax;
64 using namespace ::com::sun::star::beans;
65 using namespace ::com::sun::star::lang;
66 using namespace ::com::sun::star::container;
67 using namespace ::com::sun::star::drawing;
68 using namespace ::com::sun::star::document;
69 using namespace ::xmloff::token;
70 using ::com::sun::star::document::XEventsSupplier;
72 #define XML_TEXT_FRAME_TEXTBOX 1
73 #define XML_TEXT_FRAME_GRAPHIC 2
74 #define XML_TEXT_FRAME_OBJECT 3
75 #define XML_TEXT_FRAME_OBJECT_OLE 4
76 #define XML_TEXT_FRAME_APPLET 5
77 #define XML_TEXT_FRAME_PLUGIN 6
78 #define XML_TEXT_FRAME_FLOATING_FRAME 7
80 typedef ::std::map < const OUString, OUString, ::comphelper::UStringLess> ParamMap;
82 class XMLTextFrameContextHyperlink_Impl
84 OUString sHRef;
85 OUString sName;
86 OUString sTargetFrameName;
87 sal_Bool bMap;
89 public:
91 inline XMLTextFrameContextHyperlink_Impl( const OUString& rHRef,
92 const OUString& rName,
93 const OUString& rTargetFrameName,
94 sal_Bool bMap );
96 const OUString& GetHRef() const { return sHRef; }
97 const OUString& GetName() const { return sName; }
98 const OUString& GetTargetFrameName() const { return sTargetFrameName; }
99 sal_Bool GetMap() const { return bMap; }
102 inline XMLTextFrameContextHyperlink_Impl::XMLTextFrameContextHyperlink_Impl(
103 const OUString& rHRef, const OUString& rName,
104 const OUString& rTargetFrameName, sal_Bool bM ) :
105 sHRef( rHRef ),
106 sName( rName ),
107 sTargetFrameName( rTargetFrameName ),
108 bMap( bM )
112 // Implement Title/Description Elements UI (#i73249#)
113 class XMLTextFrameTitleOrDescContext_Impl : public SvXMLImportContext
115 OUString& mrTitleOrDesc;
117 public:
119 TYPEINFO();
121 XMLTextFrameTitleOrDescContext_Impl( SvXMLImport& rImport,
122 sal_uInt16 nPrfx,
123 const OUString& rLName,
124 OUString& rTitleOrDesc );
125 virtual ~XMLTextFrameTitleOrDescContext_Impl();
127 virtual void Characters( const OUString& rText );
130 TYPEINIT1( XMLTextFrameTitleOrDescContext_Impl, SvXMLImportContext );
132 XMLTextFrameTitleOrDescContext_Impl::XMLTextFrameTitleOrDescContext_Impl(
133 SvXMLImport& rImport,
134 sal_uInt16 nPrfx,
135 const OUString& rLName,
136 OUString& rTitleOrDesc )
137 : SvXMLImportContext( rImport, nPrfx, rLName )
138 , mrTitleOrDesc( rTitleOrDesc )
142 XMLTextFrameTitleOrDescContext_Impl::~XMLTextFrameTitleOrDescContext_Impl()
146 void XMLTextFrameTitleOrDescContext_Impl::Characters( const OUString& rText )
148 mrTitleOrDesc += rText;
151 // ------------------------------------------------------------------------
153 class XMLTextFrameParam_Impl : public SvXMLImportContext
155 public:
157 TYPEINFO();
159 XMLTextFrameParam_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
160 const OUString& rLName,
161 const ::com::sun::star::uno::Reference<
162 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
163 sal_uInt16 nType,
164 ParamMap &rParamMap);
165 virtual ~XMLTextFrameParam_Impl();
168 TYPEINIT1( XMLTextFrameParam_Impl, SvXMLImportContext );
170 XMLTextFrameParam_Impl::~XMLTextFrameParam_Impl()
174 XMLTextFrameParam_Impl::XMLTextFrameParam_Impl(
175 SvXMLImport& rImport, sal_uInt16 nPrfx,
176 const 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 SvXMLImportContext( rImport, nPrfx, rLName )
183 OUString sName, sValue;
184 sal_Bool bFoundValue = sal_False; // to allow empty values
185 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
186 for( sal_Int16 i=0; i < nAttrCount; i++ )
188 const OUString& rAttrName = xAttrList->getNameByIndex( i );
189 const OUString& rValue = xAttrList->getValueByIndex( i );
191 OUString aLocalName;
192 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
193 if ( XML_NAMESPACE_DRAW == nPrefix )
195 if( IsXMLToken(aLocalName, XML_VALUE) )
197 sValue = rValue;
198 bFoundValue=sal_True;
200 else if( IsXMLToken(aLocalName, XML_NAME) )
202 sName = rValue;
206 if (!sName.isEmpty() && bFoundValue )
207 rParamMap[sName] = sValue;
209 class XMLTextFrameContourContext_Impl : public SvXMLImportContext
211 Reference < XPropertySet > xPropSet;
213 public:
215 TYPEINFO();
217 XMLTextFrameContourContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
218 const OUString& rLName,
219 const ::com::sun::star::uno::Reference<
220 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
221 const Reference < XPropertySet >& rPropSet,
222 sal_Bool bPath );
223 virtual ~XMLTextFrameContourContext_Impl();
226 TYPEINIT1( XMLTextFrameContourContext_Impl, SvXMLImportContext );
228 XMLTextFrameContourContext_Impl::XMLTextFrameContourContext_Impl(
229 SvXMLImport& rImport,
230 sal_uInt16 nPrfx, const OUString& rLName,
231 const Reference< XAttributeList > & xAttrList,
232 const Reference < XPropertySet >& rPropSet,
233 sal_Bool bPath ) :
234 SvXMLImportContext( rImport, nPrfx, rLName ),
235 xPropSet( rPropSet )
237 OUString sD, sPoints, sViewBox;
238 sal_Bool bPixelWidth = sal_False, bPixelHeight = sal_False;
239 sal_Bool bAuto = sal_False;
240 sal_Int32 nWidth = 0;
241 sal_Int32 nHeight = 0;
243 const SvXMLTokenMap& rTokenMap =
244 GetImport().GetTextImport()->GetTextContourAttrTokenMap();
246 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
247 for( sal_Int16 i=0; i < nAttrCount; i++ )
249 const OUString& rAttrName = xAttrList->getNameByIndex( i );
250 const OUString& rValue = xAttrList->getValueByIndex( i );
252 OUString aLocalName;
253 sal_uInt16 nPrefix =
254 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
255 &aLocalName );
256 switch( rTokenMap.Get( nPrefix, aLocalName ) )
258 case XML_TOK_TEXT_CONTOUR_VIEWBOX:
259 sViewBox = rValue;
260 break;
261 case XML_TOK_TEXT_CONTOUR_D:
262 if( bPath )
263 sD = rValue;
264 break;
265 case XML_TOK_TEXT_CONTOUR_POINTS:
266 if( !bPath )
267 sPoints = rValue;
268 break;
269 case XML_TOK_TEXT_CONTOUR_WIDTH:
270 if (::sax::Converter::convertMeasurePx(nWidth, rValue))
271 bPixelWidth = sal_True;
272 else
273 GetImport().GetMM100UnitConverter().convertMeasureToCore(
274 nWidth, rValue);
275 break;
276 case XML_TOK_TEXT_CONTOUR_HEIGHT:
277 if (::sax::Converter::convertMeasurePx(nHeight, rValue))
278 bPixelHeight = sal_True;
279 else
280 GetImport().GetMM100UnitConverter().convertMeasureToCore(
281 nHeight, rValue);
282 break;
283 case XML_TOK_TEXT_CONTOUR_AUTO:
284 bAuto = IsXMLToken(rValue, XML_TRUE);
285 break;
289 OUString sContourPolyPolygon("ContourPolyPolygon");
290 Reference < XPropertySetInfo > xPropSetInfo =
291 rPropSet->getPropertySetInfo();
292 if( xPropSetInfo->hasPropertyByName(sContourPolyPolygon ) &&
293 nWidth > 0 && nHeight > 0 && bPixelWidth == bPixelHeight &&
294 !(bPath ? sD : sPoints).isEmpty() )
296 awt::Point aPoint( 0, 0 );
297 awt::Size aSize( nWidth, nHeight );
298 SdXMLImExViewBox aViewBox( sViewBox,
299 GetImport().GetMM100UnitConverter());
300 Any aAny;
301 if( bPath )
303 SdXMLImExSvgDElement aPoints( sD, aViewBox, aPoint, aSize, GetImport() );
304 aAny <<= aPoints.GetPointSequenceSequence();
306 else
308 SdXMLImExPointsElement aPoints( sPoints, aViewBox, aPoint, aSize,
309 GetImport().GetMM100UnitConverter() );
310 aAny <<= aPoints.GetPointSequenceSequence();
313 OUString sIsPixelContour("IsPixelContour");
314 xPropSet->setPropertyValue( sContourPolyPolygon, aAny );
316 if( xPropSetInfo->hasPropertyByName( sIsPixelContour ) )
318 aAny.setValue( &bPixelWidth, ::getBooleanCppuType() );
319 xPropSet->setPropertyValue( sIsPixelContour, aAny );
322 OUString sIsAutomaticContour("IsAutomaticContour");
323 if( xPropSetInfo->hasPropertyByName( sIsAutomaticContour ) )
325 aAny.setValue( &bAuto, ::getBooleanCppuType() );
326 xPropSet->setPropertyValue( sIsAutomaticContour, aAny );
331 XMLTextFrameContourContext_Impl::~XMLTextFrameContourContext_Impl()
335 // ------------------------------------------------------------------------
337 class XMLTextFrameContext_Impl : public SvXMLImportContext
339 ::com::sun::star::uno::Reference <
340 ::com::sun::star::text::XTextCursor > xOldTextCursor;
341 ::com::sun::star::uno::Reference <
342 ::com::sun::star::beans::XPropertySet > xPropSet;
343 ::com::sun::star::uno::Reference <
344 ::com::sun::star::io::XOutputStream > xBase64Stream;
346 /// old list item and block (#89891#)
347 bool mbListContextPushed;
349 const OUString sWidth;
350 const OUString sWidthType;
351 const OUString sRelativeWidth;
352 const OUString sHeight;
353 const OUString sRelativeHeight;
354 const OUString sSizeType;
355 const OUString sIsSyncWidthToHeight;
356 const OUString sIsSyncHeightToWidth;
357 const OUString sHoriOrient;
358 const OUString sHoriOrientPosition;
359 const OUString sVertOrient;
360 const OUString sVertOrientPosition;
361 const OUString sChainNextName;
362 const OUString sAnchorType;
363 const OUString sAnchorPageNo;
364 const OUString sGraphicURL;
365 const OUString sGraphicFilter;
366 const OUString sTitle;
367 const OUString sDescription;
368 const OUString sFrameStyleName;
369 const OUString sGraphicRotation;
370 const OUString sTextBoxServiceName;
371 const OUString sGraphicServiceName;
373 OUString m_sOrigName;
374 OUString sName;
375 OUString sStyleName;
376 OUString sNextName;
377 OUString sHRef;
378 OUString sFilterName;
379 OUString sCode;
380 OUString sObject;
381 OUString sArchive;
382 OUString sMimeType;
383 OUString sFrameName;
384 OUString sAppletName;
385 OUString sFilterService;
386 OUString sBase64CharsLeft;
387 OUString sTblName;
389 ParamMap aParamMap;
391 sal_Int32 nX;
392 sal_Int32 nY;
393 sal_Int32 nWidth;
394 sal_Int32 nHeight;
395 sal_Int32 nZIndex;
396 sal_Int16 nPage;
397 sal_Int16 nRotation;
398 sal_Int16 nRelWidth;
399 sal_Int16 nRelHeight;
401 sal_uInt16 nType;
402 ::com::sun::star::text::TextContentAnchorType eAnchorType;
404 sal_Bool bMayScript : 1;
405 sal_Bool bMinWidth : 1;
406 sal_Bool bMinHeight : 1;
407 sal_Bool bSyncWidth : 1;
408 sal_Bool bSyncHeight : 1;
409 sal_Bool bCreateFailed : 1;
410 sal_Bool bOwnBase64Stream : 1;
412 void Create( sal_Bool bHRefOrBase64 );
414 public:
416 TYPEINFO();
418 sal_Bool CreateIfNotThere();
419 const OUString& GetHRef() const { return sHRef; }
421 XMLTextFrameContext_Impl( SvXMLImport& rImport,
422 sal_uInt16 nPrfx,
423 const OUString& rLName,
424 const ::com::sun::star::uno::Reference<
425 ::com::sun::star::xml::sax::XAttributeList > & rAttrList,
426 ::com::sun::star::text::TextContentAnchorType eAnchorType,
427 sal_uInt16 nType,
428 const ::com::sun::star::uno::Reference<
429 ::com::sun::star::xml::sax::XAttributeList > & rFrameAttrList );
430 virtual ~XMLTextFrameContext_Impl();
432 virtual void EndElement();
434 virtual void Characters( const OUString& rChars );
436 SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
437 const OUString& rLocalName,
438 const ::com::sun::star::uno::Reference<
439 ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
441 void SetHyperlink( const OUString& rHRef,
442 const OUString& rName,
443 const OUString& rTargetFrameName,
444 sal_Bool bMap );
446 // Implement Title/Description Elements UI (#i73249#)
447 void SetTitle( const OUString& rTitle );
449 void SetDesc( const OUString& rDesc );
451 void SetName();
453 ::com::sun::star::text::TextContentAnchorType GetAnchorType() const { return eAnchorType; }
455 const ::com::sun::star::uno::Reference <
456 ::com::sun::star::beans::XPropertySet >& GetPropSet() const { return xPropSet; }
459 TYPEINIT1( XMLTextFrameContext_Impl, SvXMLImportContext );
461 void XMLTextFrameContext_Impl::Create( sal_Bool /*bHRefOrBase64*/ )
463 UniReference < XMLTextImportHelper > xTextImportHelper =
464 GetImport().GetTextImport();
466 switch ( nType)
468 case XML_TEXT_FRAME_OBJECT:
469 case XML_TEXT_FRAME_OBJECT_OLE:
470 if( xBase64Stream.is() )
472 OUString sURL( GetImport().ResolveEmbeddedObjectURLFromBase64() );
473 if( !sURL.isEmpty() )
474 xPropSet = GetImport().GetTextImport()
475 ->createAndInsertOLEObject( GetImport(), sURL,
476 sStyleName,
477 sTblName,
478 nWidth, nHeight );
480 else if( !sHRef.isEmpty() )
482 OUString sURL( GetImport().ResolveEmbeddedObjectURL( sHRef,
483 OUString() ) );
485 if( GetImport().IsPackageURL( sHRef ) )
487 xPropSet = GetImport().GetTextImport()
488 ->createAndInsertOLEObject( GetImport(), sURL,
489 sStyleName,
490 sTblName,
491 nWidth, nHeight );
493 else
495 // it should be an own OOo link that has no storage persistance
496 xPropSet = GetImport().GetTextImport()
497 ->createAndInsertOOoLink( GetImport(),
498 sURL,
499 sStyleName,
500 sTblName,
501 nWidth, nHeight );
504 else
506 OUString sURL( "vnd.sun.star.ServiceName:" );
507 sURL += sFilterService;
508 xPropSet = GetImport().GetTextImport()
509 ->createAndInsertOLEObject( GetImport(), sURL,
510 sStyleName,
511 sTblName,
512 nWidth, nHeight );
515 break;
516 case XML_TEXT_FRAME_APPLET:
518 xPropSet = GetImport().GetTextImport()
519 ->createAndInsertApplet( sAppletName, sCode,
520 bMayScript, sHRef,
521 nWidth, nHeight);
522 break;
524 case XML_TEXT_FRAME_PLUGIN:
526 if(!sHRef.isEmpty())
527 GetImport().GetAbsoluteReference(sHRef);
528 xPropSet = GetImport().GetTextImport()
529 ->createAndInsertPlugin( sMimeType, sHRef,
530 nWidth, nHeight);
532 break;
534 case XML_TEXT_FRAME_FLOATING_FRAME:
536 xPropSet = GetImport().GetTextImport()
537 ->createAndInsertFloatingFrame( sFrameName, sHRef,
538 sStyleName,
539 nWidth, nHeight);
540 break;
542 default:
544 Reference<XMultiServiceFactory> xFactory( GetImport().GetModel(),
545 UNO_QUERY );
546 if( xFactory.is() )
548 OUString sServiceName;
549 switch( nType )
551 case XML_TEXT_FRAME_TEXTBOX: sServiceName = sTextBoxServiceName; break;
552 case XML_TEXT_FRAME_GRAPHIC: sServiceName = sGraphicServiceName; break;
554 Reference<XInterface> xIfc = xFactory->createInstance( sServiceName );
555 DBG_ASSERT( xIfc.is(), "couldn't create frame" );
556 if( xIfc.is() )
557 xPropSet = Reference < XPropertySet >( xIfc, UNO_QUERY );
562 if( !xPropSet.is() )
564 bCreateFailed = sal_True;
565 return;
568 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
570 // set name
571 Reference < XNamed > xNamed( xPropSet, UNO_QUERY );
572 if( xNamed.is() )
574 OUString sOrigName( xNamed->getName() );
575 if( sOrigName.isEmpty() ||
576 (!sName.isEmpty() && sOrigName != sName) )
578 OUString sOldName( sName );
579 sal_Int32 i = 0;
580 while( xTextImportHelper->HasFrameByName( sName ) )
582 sName = sOldName;
583 sName += OUString::valueOf( ++i );
585 xNamed->setName( sName );
586 if( sName != sOldName )
587 xTextImportHelper->GetRenameMap().Add( XML_TEXT_RENAME_TYPE_FRAME,
588 sOldName, sName );
592 // frame style
593 XMLPropStyleContext *pStyle = 0;
594 if( !sStyleName.isEmpty() )
596 pStyle = xTextImportHelper->FindAutoFrameStyle( sStyleName );
597 if( pStyle )
598 sStyleName = pStyle->GetParentName();
601 Any aAny;
602 if( !sStyleName.isEmpty() )
604 OUString sDisplayStyleName( GetImport().GetStyleDisplayName(
605 XML_STYLE_FAMILY_SD_GRAPHICS_ID, sStyleName ) );
606 const Reference < XNameContainer > & rStyles =
607 xTextImportHelper->GetFrameStyles();
608 if( rStyles.is() &&
609 rStyles->hasByName( sDisplayStyleName ) )
611 aAny <<= sDisplayStyleName;
612 xPropSet->setPropertyValue( sFrameStyleName, aAny );
616 // anchor type (must be set before any other properties, because
617 // otherwise some orientations cannot be set or will be changed
618 // afterwards)
619 aAny <<= eAnchorType;
620 xPropSet->setPropertyValue( sAnchorType, aAny );
622 // hard properties
623 if( pStyle )
624 pStyle->FillPropertySet( xPropSet );
627 // x and y
628 sal_Int16 nHoriOrient = HoriOrientation::NONE;
629 aAny = xPropSet->getPropertyValue( sHoriOrient );
630 aAny >>= nHoriOrient;
631 if( HoriOrientation::NONE == nHoriOrient )
633 aAny <<= nX;
634 xPropSet->setPropertyValue( sHoriOrientPosition, aAny );
637 sal_Int16 nVertOrient = VertOrientation::NONE;
638 aAny = xPropSet->getPropertyValue( sVertOrient );
639 aAny >>= nVertOrient;
640 if( VertOrientation::NONE == nVertOrient )
642 aAny <<= nY;
643 xPropSet->setPropertyValue( sVertOrientPosition, aAny );
646 // width
647 if( nWidth > 0 )
649 aAny <<= nWidth;
650 xPropSet->setPropertyValue( sWidth, aAny );
652 if( nRelWidth > 0 || nWidth > 0 )
654 aAny <<= nRelWidth;
655 xPropSet->setPropertyValue( sRelativeWidth, aAny );
657 if( bSyncWidth || nWidth > 0 )
659 sal_Bool bTmp = bSyncWidth;
660 aAny.setValue( &bTmp, ::getBooleanCppuType() );
661 xPropSet->setPropertyValue( sIsSyncWidthToHeight, aAny );
663 if( xPropSetInfo->hasPropertyByName( sWidthType ) &&
664 (bMinWidth || nWidth > 0 || nRelWidth > 0 ) )
666 sal_Int16 nSizeType =
667 (bMinWidth && XML_TEXT_FRAME_TEXTBOX == nType) ? SizeType::MIN
668 : SizeType::FIX;
669 aAny <<= nSizeType;
670 xPropSet->setPropertyValue( sWidthType, aAny );
673 if( nHeight > 0 )
675 aAny <<= nHeight;
676 xPropSet->setPropertyValue( sHeight, aAny );
678 if( nRelHeight > 0 || nHeight > 0 )
680 aAny <<= nRelHeight;
681 xPropSet->setPropertyValue( sRelativeHeight, aAny );
683 if( bSyncHeight || nHeight > 0 )
685 sal_Bool bTmp = bSyncHeight;
686 aAny.setValue( &bTmp, ::getBooleanCppuType() );
687 xPropSet->setPropertyValue( sIsSyncHeightToWidth, aAny );
689 if( xPropSetInfo->hasPropertyByName( sSizeType ) &&
690 (bMinHeight || nHeight > 0 || nRelHeight > 0 ) )
692 sal_Int16 nSizeType =
693 (bMinHeight && XML_TEXT_FRAME_TEXTBOX == nType) ? SizeType::MIN
694 : SizeType::FIX;
695 aAny <<= nSizeType;
696 xPropSet->setPropertyValue( sSizeType, aAny );
699 if( XML_TEXT_FRAME_GRAPHIC == nType )
701 // URL
702 OSL_ENSURE( !sHRef.isEmpty() || xBase64Stream.is(),
703 "neither URL nor base64 image data given" );
704 UniReference < XMLTextImportHelper > xTxtImport =
705 GetImport().GetTextImport();
706 if( !sHRef.isEmpty() )
708 sal_Bool bForceLoad = xTxtImport->IsInsertMode() ||
709 xTxtImport->IsBlockMode() ||
710 xTxtImport->IsStylesOnlyMode() ||
711 xTxtImport->IsOrganizerMode();
712 sHRef = GetImport().ResolveGraphicObjectURL( sHRef, !bForceLoad );
714 else if( xBase64Stream.is() )
716 sHRef = GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream );
717 xBase64Stream = 0;
719 aAny <<= sHRef;
720 xPropSet->setPropertyValue( sGraphicURL, aAny );
722 // filter name
723 aAny <<=sFilterName;
724 xPropSet->setPropertyValue( sGraphicFilter, aAny );
726 // rotation
727 aAny <<= nRotation;
728 xPropSet->setPropertyValue( sGraphicRotation, aAny );
731 // page number (must be set after the frame is inserted, because it
732 // will be overwritten then inserting the frame.
733 if( TextContentAnchorType_AT_PAGE == eAnchorType && nPage > 0 )
735 aAny <<= nPage;
736 xPropSet->setPropertyValue( sAnchorPageNo, aAny );
739 if( XML_TEXT_FRAME_OBJECT != nType &&
740 XML_TEXT_FRAME_OBJECT_OLE != nType &&
741 XML_TEXT_FRAME_APPLET != nType &&
742 XML_TEXT_FRAME_PLUGIN!= nType &&
743 XML_TEXT_FRAME_FLOATING_FRAME != nType)
745 Reference < XTextContent > xTxtCntnt( xPropSet, UNO_QUERY );
746 xTextImportHelper->InsertTextContent( xTxtCntnt );
749 // #107848#
750 // Make adding the shepe to Z-Ordering dependent from if we are
751 // inside a inside_deleted_section (redlining). That is necessary
752 // since the shape will be removed again later. It would lead to
753 // errors if it would stay inside the Z-Ordering. Thus, the
754 // easiest way to solve that conflict is to not add it here.
755 if(!GetImport().HasTextImport()
756 || !GetImport().GetTextImport()->IsInsideDeleteContext())
758 Reference < XShape > xShape( xPropSet, UNO_QUERY );
760 GetImport().GetShapeImport()->shapeWithZIndexAdded( xShape, nZIndex );
763 if( XML_TEXT_FRAME_TEXTBOX == nType )
765 xTextImportHelper->ConnectFrameChains( sName, sNextName, xPropSet );
766 Reference < XTextFrame > xTxtFrame( xPropSet, UNO_QUERY );
767 Reference < XText > xTxt = xTxtFrame->getText();
768 xOldTextCursor = xTextImportHelper->GetCursor();
769 xTextImportHelper->SetCursor( xTxt->createTextCursor() );
771 // remember old list item and block (#89892#) and reset them
772 // for the text frame
773 xTextImportHelper->PushListContext();
774 mbListContextPushed = true;
779 void XMLTextFrameContext::removeGraphicFromImportContext(const SvXMLImportContext& rContext) const
781 const XMLTextFrameContext_Impl* pXMLTextFrameContext_Impl = dynamic_cast< const XMLTextFrameContext_Impl* >(&rContext);
783 if(pXMLTextFrameContext_Impl)
787 // just dispose to delete
788 uno::Reference< lang::XComponent > xComp(pXMLTextFrameContext_Impl->GetPropSet(), UNO_QUERY);
790 if(xComp.is())
792 xComp->dispose();
795 catch( uno::Exception& )
797 OSL_FAIL( "Error in cleanup of multiple graphic object import (!)" );
802 OUString XMLTextFrameContext::getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const
804 OUString aRetval;
805 const XMLTextFrameContext_Impl* pXMLTextFrameContext_Impl = dynamic_cast< const XMLTextFrameContext_Impl* >(&rContext);
807 if(pXMLTextFrameContext_Impl)
809 return pXMLTextFrameContext_Impl->GetHRef();
812 return aRetval;
815 sal_Bool XMLTextFrameContext_Impl::CreateIfNotThere()
817 if( !xPropSet.is() &&
818 ( XML_TEXT_FRAME_OBJECT_OLE == nType ||
819 XML_TEXT_FRAME_GRAPHIC == nType ) &&
820 xBase64Stream.is() && !bCreateFailed )
822 if( bOwnBase64Stream )
823 xBase64Stream->closeOutput();
824 Create( sal_True );
827 return xPropSet.is();
830 XMLTextFrameContext_Impl::XMLTextFrameContext_Impl(
831 SvXMLImport& rImport,
832 sal_uInt16 nPrfx, const OUString& rLName,
833 const Reference< XAttributeList > & rAttrList,
834 TextContentAnchorType eATyp,
835 sal_uInt16 nNewType,
836 const Reference< XAttributeList > & rFrameAttrList )
837 : SvXMLImportContext( rImport, nPrfx, rLName )
838 , mbListContextPushed( false )
839 , sWidth("Width")
840 , sWidthType("WidthType")
841 , sRelativeWidth("RelativeWidth")
842 , sHeight("Height")
843 , sRelativeHeight("RelativeHeight")
844 , sSizeType("SizeType")
845 , sIsSyncWidthToHeight("IsSyncWidthToHeight")
846 , sIsSyncHeightToWidth("IsSyncHeightToWidth")
847 , sHoriOrient("HoriOrient")
848 , sHoriOrientPosition("HoriOrientPosition")
849 , sVertOrient("VertOrient")
850 , sVertOrientPosition("VertOrientPosition")
851 , sChainNextName("ChainNextName")
852 , sAnchorType("AnchorType")
853 , sAnchorPageNo("AnchorPageNo")
854 , sGraphicURL("GraphicURL")
855 , sGraphicFilter("GraphicFilter")
856 , sTitle("Title")
857 , sDescription("Description")
858 , sFrameStyleName("FrameStyleName")
859 , sGraphicRotation("GraphicRotation")
860 , sTextBoxServiceName("com.sun.star.text.TextFrame")
861 , sGraphicServiceName("com.sun.star.text.GraphicObject")
862 , nType( nNewType )
863 , eAnchorType( eATyp )
865 nX = 0;
866 nY = 0;
867 nWidth = 0;
868 nHeight = 0;
869 nZIndex = -1;
870 nPage = 0;
871 nRotation = 0;
872 nRelWidth = 0;
873 nRelHeight = 0;
874 bMayScript = sal_False;
876 bMinHeight = sal_False;
877 bMinWidth = sal_False;
878 bSyncWidth = sal_False;
879 bSyncHeight = sal_False;
880 bCreateFailed = sal_False;
881 bOwnBase64Stream = sal_False;
883 UniReference < XMLTextImportHelper > xTxtImport =
884 GetImport().GetTextImport();
885 const SvXMLTokenMap& rTokenMap =
886 xTxtImport->GetTextFrameAttrTokenMap();
888 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
889 sal_Int16 nTotalAttrCount = nAttrCount + (rFrameAttrList.is() ? rFrameAttrList->getLength() : 0);
890 for( sal_Int16 i=0; i < nTotalAttrCount; i++ )
892 const OUString& rAttrName =
893 i < nAttrCount ? rAttrList->getNameByIndex( i ) : rFrameAttrList->getNameByIndex( i-nAttrCount );
894 const OUString& rValue =
895 i < nAttrCount ? rAttrList->getValueByIndex( i ): rFrameAttrList->getValueByIndex( i-nAttrCount );
897 OUString aLocalName;
898 sal_uInt16 nPrefix =
899 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
900 &aLocalName );
901 switch( rTokenMap.Get( nPrefix, aLocalName ) )
903 case XML_TOK_TEXT_FRAME_STYLE_NAME:
904 sStyleName = rValue;
905 break;
906 case XML_TOK_TEXT_FRAME_NAME:
907 m_sOrigName = rValue;
908 sName = rValue;
909 break;
910 case XML_TOK_TEXT_FRAME_FRAME_NAME:
911 sFrameName = rValue;
912 break;
913 case XML_TOK_TEXT_FRAME_APPLET_NAME:
914 sAppletName = rValue;
915 break;
916 case XML_TOK_TEXT_FRAME_ANCHOR_TYPE:
917 if( TextContentAnchorType_AT_PARAGRAPH == eAnchorType ||
918 TextContentAnchorType_AT_CHARACTER == eAnchorType ||
919 TextContentAnchorType_AS_CHARACTER == eAnchorType )
922 TextContentAnchorType eNew;
923 if( XMLAnchorTypePropHdl::convert( rValue, eNew ) &&
924 ( TextContentAnchorType_AT_PARAGRAPH == eNew ||
925 TextContentAnchorType_AT_CHARACTER == eNew ||
926 TextContentAnchorType_AS_CHARACTER == eNew ||
927 TextContentAnchorType_AT_PAGE == eNew) )
928 eAnchorType = eNew;
930 break;
931 case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER:
933 sal_Int32 nTmp;
934 if (::sax::Converter::convertNumber(nTmp, rValue, 1, SHRT_MAX))
935 nPage = (sal_Int16)nTmp;
937 break;
938 case XML_TOK_TEXT_FRAME_X:
939 GetImport().GetMM100UnitConverter().convertMeasureToCore(
940 nX, rValue);
941 break;
942 case XML_TOK_TEXT_FRAME_Y:
943 GetImport().GetMM100UnitConverter().convertMeasureToCore(
944 nY, rValue );
945 break;
946 case XML_TOK_TEXT_FRAME_WIDTH:
947 // relative widths are obsolete since SRC617. Remove them some day!
948 if( rValue.indexOf( '%' ) != -1 )
950 sal_Int32 nTmp;
951 ::sax::Converter::convertPercent( nTmp, rValue );
952 nRelWidth = (sal_Int16)nTmp;
954 else
956 GetImport().GetMM100UnitConverter().convertMeasureToCore(
957 nWidth, rValue, 0 );
959 break;
960 case XML_TOK_TEXT_FRAME_REL_WIDTH:
961 if( IsXMLToken(rValue, XML_SCALE) )
963 bSyncWidth = sal_True;
965 else
967 sal_Int32 nTmp;
968 if (::sax::Converter::convertPercent( nTmp, rValue ))
969 nRelWidth = (sal_Int16)nTmp;
971 break;
972 case XML_TOK_TEXT_FRAME_MIN_WIDTH:
973 if( rValue.indexOf( '%' ) != -1 )
975 sal_Int32 nTmp;
976 ::sax::Converter::convertPercent( nTmp, rValue );
977 nRelWidth = (sal_Int16)nTmp;
979 else
981 GetImport().GetMM100UnitConverter().convertMeasureToCore(
982 nWidth, rValue, 0 );
984 bMinWidth = sal_True;
985 break;
986 case XML_TOK_TEXT_FRAME_HEIGHT:
987 // relative heights are obsolete since SRC617. Remove them some day!
988 if( rValue.indexOf( '%' ) != -1 )
990 sal_Int32 nTmp;
991 ::sax::Converter::convertPercent( nTmp, rValue );
992 nRelHeight = (sal_Int16)nTmp;
994 else
996 GetImport().GetMM100UnitConverter().convertMeasureToCore(
997 nHeight, rValue, 0 );
999 break;
1000 case XML_TOK_TEXT_FRAME_REL_HEIGHT:
1001 if( IsXMLToken( rValue, XML_SCALE ) )
1003 bSyncHeight = sal_True;
1005 else if( IsXMLToken( rValue, XML_SCALE_MIN ) )
1007 bSyncHeight = sal_True;
1008 bMinHeight = sal_True;
1010 else
1012 sal_Int32 nTmp;
1013 if (::sax::Converter::convertPercent( nTmp, rValue ))
1014 nRelHeight = (sal_Int16)nTmp;
1016 break;
1017 case XML_TOK_TEXT_FRAME_MIN_HEIGHT:
1018 if( rValue.indexOf( '%' ) != -1 )
1020 sal_Int32 nTmp;
1021 ::sax::Converter::convertPercent( nTmp, rValue );
1022 nRelHeight = (sal_Int16)nTmp;
1024 else
1026 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1027 nHeight, rValue, 0 );
1029 bMinHeight = sal_True;
1030 break;
1031 case XML_TOK_TEXT_FRAME_Z_INDEX:
1032 ::sax::Converter::convertNumber( nZIndex, rValue, -1 );
1033 break;
1034 case XML_TOK_TEXT_FRAME_NEXT_CHAIN_NAME:
1035 sNextName = rValue;
1036 break;
1037 case XML_TOK_TEXT_FRAME_HREF:
1038 sHRef = rValue;
1039 break;
1040 case XML_TOK_TEXT_FRAME_FILTER_NAME:
1041 sFilterName = rValue;
1042 break;
1043 case XML_TOK_TEXT_FRAME_TRANSFORM:
1045 OUString sValue( rValue );
1046 sValue = sValue.trim();
1047 const OUString aRotate(GetXMLToken(XML_ROTATE));
1048 const sal_Int32 nRotateLen(aRotate.getLength());
1049 sal_Int32 nLen = sValue.getLength();
1050 if( nLen >= nRotateLen+3 &&
1051 0 == sValue.compareTo( aRotate, nRotateLen ) &&
1052 '(' == sValue[nRotateLen] &&
1053 ')' == sValue[nLen-1] )
1055 sValue = sValue.copy( nRotateLen+1, nLen-(nRotateLen+2) );
1056 sValue = sValue.trim();
1057 sal_Int32 nVal;
1058 if (::sax::Converter::convertNumber( nVal, sValue ))
1059 nRotation = (sal_Int16)(nVal % 360 );
1062 break;
1063 case XML_TOK_TEXT_FRAME_CODE:
1064 sCode = rValue;
1065 break;
1066 case XML_TOK_TEXT_FRAME_OBJECT:
1067 sObject = rValue;
1068 break;
1069 case XML_TOK_TEXT_FRAME_ARCHIVE:
1070 sArchive = rValue;
1071 break;
1072 case XML_TOK_TEXT_FRAME_MAY_SCRIPT:
1073 bMayScript = IsXMLToken( rValue, XML_TRUE );
1074 break;
1075 case XML_TOK_TEXT_FRAME_MIME_TYPE:
1076 sMimeType = rValue;
1077 break;
1078 case XML_TOK_TEXT_FRAME_NOTIFY_ON_UPDATE:
1079 sTblName = rValue;
1080 break;
1084 if( ( (XML_TEXT_FRAME_GRAPHIC == nType ||
1085 XML_TEXT_FRAME_OBJECT == nType ||
1086 XML_TEXT_FRAME_OBJECT_OLE == nType) &&
1087 sHRef.isEmpty() ) ||
1088 ( XML_TEXT_FRAME_APPLET == nType && sCode.isEmpty() ) ||
1089 ( XML_TEXT_FRAME_PLUGIN == nType &&
1090 sHRef.isEmpty() && sMimeType.isEmpty() ) )
1091 return; // no URL: no image or OLE object
1093 Create( sal_True );
1096 XMLTextFrameContext_Impl::~XMLTextFrameContext_Impl()
1100 void XMLTextFrameContext_Impl::EndElement()
1102 CreateIfNotThere();
1104 if( xOldTextCursor.is() )
1106 GetImport().GetTextImport()->DeleteParagraph();
1107 GetImport().GetTextImport()->SetCursor( xOldTextCursor );
1110 // reinstall old list item (if necessary) #89892#
1111 if (mbListContextPushed) {
1112 GetImport().GetTextImport()->PopListContext();
1115 if (( nType == XML_TEXT_FRAME_APPLET || nType == XML_TEXT_FRAME_PLUGIN ) && xPropSet.is())
1116 GetImport().GetTextImport()->endAppletOrPlugin( xPropSet, aParamMap);
1119 SvXMLImportContext *XMLTextFrameContext_Impl::CreateChildContext(
1120 sal_uInt16 nPrefix,
1121 const OUString& rLocalName,
1122 const Reference< XAttributeList > & xAttrList )
1124 SvXMLImportContext *pContext = 0;
1126 if( XML_NAMESPACE_DRAW == nPrefix )
1128 if ( (nType == XML_TEXT_FRAME_APPLET || nType == XML_TEXT_FRAME_PLUGIN) &&
1129 IsXMLToken( rLocalName, XML_PARAM ) )
1131 pContext = new XMLTextFrameParam_Impl( GetImport(),
1132 nPrefix, rLocalName,
1133 xAttrList, nType, aParamMap );
1136 else if( (XML_NAMESPACE_OFFICE == nPrefix) )
1138 if( IsXMLToken( rLocalName, XML_BINARY_DATA ) )
1140 if( !xPropSet.is() && !xBase64Stream.is() && !bCreateFailed )
1142 switch( nType )
1144 case XML_TEXT_FRAME_GRAPHIC:
1145 xBase64Stream =
1146 GetImport().GetStreamForGraphicObjectURLFromBase64();
1147 break;
1148 case XML_TEXT_FRAME_OBJECT_OLE:
1149 xBase64Stream =
1150 GetImport().GetStreamForEmbeddedObjectURLFromBase64();
1151 break;
1153 if( xBase64Stream.is() )
1154 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
1155 rLocalName, xAttrList,
1156 xBase64Stream );
1160 // Correction of condition which also avoids warnings. (#i100480#)
1161 if( !pContext &&
1162 ( XML_TEXT_FRAME_OBJECT == nType &&
1163 ( ( XML_NAMESPACE_OFFICE == nPrefix &&
1164 IsXMLToken( rLocalName, XML_DOCUMENT ) ) ||
1165 ( XML_NAMESPACE_MATH == nPrefix &&
1166 IsXMLToken( rLocalName, XML_MATH ) ) ) ) )
1168 if( !xPropSet.is() && !bCreateFailed )
1170 XMLEmbeddedObjectImportContext *pEContext =
1171 new XMLEmbeddedObjectImportContext( GetImport(), nPrefix,
1172 rLocalName, xAttrList );
1173 sFilterService = pEContext->GetFilterServiceName();
1174 if( !sFilterService.isEmpty() )
1176 Create( sal_False );
1177 if( xPropSet.is() )
1179 Reference < XEmbeddedObjectSupplier > xEOS( xPropSet,
1180 UNO_QUERY );
1181 OSL_ENSURE( xEOS.is(),
1182 "no embedded object supplier for own object" );
1183 Reference<com::sun::star::lang::XComponent> aXComponent(xEOS->getEmbeddedObject());
1184 pEContext->SetComponent( aXComponent );
1187 pContext = pEContext;
1190 if( !pContext && xOldTextCursor.is() ) // text-box
1191 pContext = GetImport().GetTextImport()->CreateTextChildContext(
1192 GetImport(), nPrefix, rLocalName, xAttrList,
1193 XML_TEXT_TYPE_TEXTBOX );
1195 if( !pContext )
1196 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1198 return pContext;
1201 void XMLTextFrameContext_Impl::Characters( const OUString& rChars )
1203 if( ( XML_TEXT_FRAME_OBJECT_OLE == nType ||
1204 XML_TEXT_FRAME_GRAPHIC == nType) &&
1205 !xPropSet.is() && !bCreateFailed )
1207 OUString sTrimmedChars( rChars. trim() );
1208 if( !sTrimmedChars.isEmpty() )
1210 if( !xBase64Stream.is() )
1212 if( XML_TEXT_FRAME_GRAPHIC == nType )
1214 xBase64Stream =
1215 GetImport().GetStreamForGraphicObjectURLFromBase64();
1217 else
1219 xBase64Stream =
1220 GetImport().GetStreamForEmbeddedObjectURLFromBase64();
1222 if( xBase64Stream.is() )
1223 bOwnBase64Stream = sal_True;
1225 if( bOwnBase64Stream && xBase64Stream.is() )
1227 OUString sChars;
1228 if( !sBase64CharsLeft.isEmpty() )
1230 sChars = sBase64CharsLeft;
1231 sChars += sTrimmedChars;
1232 sBase64CharsLeft = OUString();
1234 else
1236 sChars = sTrimmedChars;
1238 Sequence< sal_Int8 > aBuffer( (sChars.getLength() / 4) * 3 );
1239 sal_Int32 nCharsDecoded =
1240 ::sax::Converter::decodeBase64SomeChars( aBuffer, sChars );
1241 xBase64Stream->writeBytes( aBuffer );
1242 if( nCharsDecoded != sChars.getLength() )
1243 sBase64CharsLeft = sChars.copy( nCharsDecoded );
1249 void XMLTextFrameContext_Impl::SetHyperlink( const OUString& rHRef,
1250 const OUString& rName,
1251 const OUString& rTargetFrameName,
1252 sal_Bool bMap )
1254 static OUString s_HyperLinkURL("HyperLinkURL");
1255 static OUString s_HyperLinkName("HyperLinkName");
1256 static OUString s_HyperLinkTarget("HyperLinkTarget");
1257 static OUString s_ServerMap("ServerMap");
1258 if( !xPropSet.is() )
1259 return;
1261 UniReference< XMLTextImportHelper > xTxtImp = GetImport().GetTextImport();
1262 Reference < XPropertySetInfo > xPropSetInfo =
1263 xPropSet->getPropertySetInfo();
1264 if( !xPropSetInfo.is() ||
1265 !xPropSetInfo->hasPropertyByName(s_HyperLinkURL))
1266 return;
1268 Any aAny;
1269 aAny <<= rHRef;
1270 xPropSet->setPropertyValue( s_HyperLinkURL, aAny );
1272 if (xPropSetInfo->hasPropertyByName(s_HyperLinkName))
1274 aAny <<= rName;
1275 xPropSet->setPropertyValue(s_HyperLinkName, aAny);
1278 if (xPropSetInfo->hasPropertyByName(s_HyperLinkTarget))
1280 aAny <<= rTargetFrameName;
1281 xPropSet->setPropertyValue( s_HyperLinkTarget, aAny );
1284 if (xPropSetInfo->hasPropertyByName(s_ServerMap))
1286 aAny.setValue( &bMap, ::getBooleanCppuType() );
1287 xPropSet->setPropertyValue(s_ServerMap, aAny);
1291 void XMLTextFrameContext_Impl::SetName()
1293 Reference<XNamed> xNamed(xPropSet, UNO_QUERY);
1294 if (!m_sOrigName.isEmpty() && xNamed.is())
1296 OUString const name(xNamed->getName());
1297 if (name != m_sOrigName)
1301 xNamed->setName(m_sOrigName);
1303 catch (uno::Exception const& e)
1304 { // fdo#71698 document contains 2 frames with same draw:name
1305 SAL_INFO("xmloff.text", "SetName(): exception setting \""
1306 << m_sOrigName << "\": " << e.Message);
1312 // Implement Title/Description Elements UI (#i73249#)
1313 void XMLTextFrameContext_Impl::SetTitle( const OUString& rTitle )
1315 if ( xPropSet.is() )
1317 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1318 if( xPropSetInfo->hasPropertyByName( sTitle ) )
1320 xPropSet->setPropertyValue( sTitle, makeAny( rTitle ) );
1325 void XMLTextFrameContext_Impl::SetDesc( const OUString& rDesc )
1327 if ( xPropSet.is() )
1329 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1330 if( xPropSetInfo->hasPropertyByName( sDescription ) )
1332 xPropSet->setPropertyValue( sDescription, makeAny( rDesc ) );
1337 //-----------------------------------------------------------------------------------------------------
1339 TYPEINIT1( XMLTextFrameContext, SvXMLImportContext );
1341 sal_Bool XMLTextFrameContext::CreateIfNotThere( ::com::sun::star::uno::Reference <
1342 ::com::sun::star::beans::XPropertySet >& rPropSet )
1344 SvXMLImportContext *pContext = &m_xImplContext;
1345 XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1346 if( pImpl )
1348 if( pImpl->CreateIfNotThere() )
1349 rPropSet = pImpl->GetPropSet();
1352 return rPropSet.is();
1355 XMLTextFrameContext::XMLTextFrameContext(
1356 SvXMLImport& rImport,
1357 sal_uInt16 nPrfx, const OUString& rLName,
1358 const Reference< XAttributeList > & xAttrList,
1359 TextContentAnchorType eATyp )
1360 : SvXMLImportContext( rImport, nPrfx, rLName )
1361 , MultiImageImportHelper()
1362 , m_xAttrList( new SvXMLAttributeList( xAttrList ) )
1363 , m_pHyperlink( 0 )
1364 // Implement Title/Description Elements UI (#i73249#)
1365 , m_sTitle()
1366 , m_sDesc()
1367 , m_eDefaultAnchorType( eATyp )
1368 // Shapes in Writer cannot be named via context menu (#i51726#)
1369 , m_HasAutomaticStyleWithoutParentStyle( sal_False )
1370 , m_bSupportsReplacement( sal_False )
1372 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1373 for( sal_Int16 i=0; i < nAttrCount; i++ )
1375 const OUString& rAttrName = xAttrList->getNameByIndex( i );
1377 OUString aLocalName;
1378 sal_uInt16 nPrefix =
1379 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
1380 // New distinguish attribute between Writer objects and Draw objects is:
1381 // Draw objects have an automatic style without a parent style (#i51726#)
1382 if ( XML_NAMESPACE_DRAW == nPrefix &&
1383 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1385 OUString aStyleName = xAttrList->getValueByIndex( i );
1386 if( !aStyleName.isEmpty() )
1388 UniReference < XMLTextImportHelper > xTxtImport =
1389 GetImport().GetTextImport();
1390 XMLPropStyleContext* pStyle( 0L );
1391 pStyle = xTxtImport->FindAutoFrameStyle( aStyleName );
1392 if ( pStyle && pStyle->GetParentName().isEmpty() )
1394 m_HasAutomaticStyleWithoutParentStyle = sal_True;
1398 else if ( XML_NAMESPACE_TEXT == nPrefix &&
1399 IsXMLToken( aLocalName, XML_ANCHOR_TYPE ) )
1401 TextContentAnchorType eNew;
1402 if( XMLAnchorTypePropHdl::convert( xAttrList->getValueByIndex(i),
1403 eNew ) &&
1404 ( TextContentAnchorType_AT_PARAGRAPH == eNew ||
1405 TextContentAnchorType_AT_CHARACTER == eNew ||
1406 TextContentAnchorType_AS_CHARACTER == eNew ||
1407 TextContentAnchorType_AT_PAGE == eNew) )
1408 m_eDefaultAnchorType = eNew;
1413 XMLTextFrameContext::~XMLTextFrameContext()
1415 delete m_pHyperlink;
1418 void XMLTextFrameContext::EndElement()
1420 /// solve if multiple image child contexts were imported
1421 SvXMLImportContextRef const pMultiContext(solveMultipleImages());
1423 SvXMLImportContext const*const pContext =
1424 (pMultiContext) ? &pMultiContext : &m_xImplContext;
1425 XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1426 assert(!pMultiContext || pImpl);
1427 if( pImpl )
1429 pImpl->CreateIfNotThere();
1431 // fdo#68839: in case the surviving image was not the first one,
1432 // it will have a counter added to its name - set the original name
1433 if (pMultiContext) // do this only when necessary; esp. not for text
1434 { // frames that may have entries in GetRenameMap()!
1435 pImpl->SetName();
1438 if( !m_sTitle.isEmpty() )
1440 pImpl->SetTitle( m_sTitle );
1442 if( !m_sDesc.isEmpty() )
1444 pImpl->SetDesc( m_sDesc );
1447 if( m_pHyperlink )
1449 pImpl->SetHyperlink( m_pHyperlink->GetHRef(), m_pHyperlink->GetName(),
1450 m_pHyperlink->GetTargetFrameName(), m_pHyperlink->GetMap() );
1451 delete m_pHyperlink;
1452 m_pHyperlink = 0;
1458 SvXMLImportContext *XMLTextFrameContext::CreateChildContext(
1459 sal_uInt16 p_nPrefix,
1460 const OUString& rLocalName,
1461 const Reference< XAttributeList > & xAttrList )
1463 SvXMLImportContext *pContext = 0;
1465 if( !m_xImplContext.Is() )
1467 // no child exists
1468 if( XML_NAMESPACE_DRAW == p_nPrefix )
1470 sal_uInt16 nFrameType = USHRT_MAX;
1471 if( IsXMLToken( rLocalName, XML_TEXT_BOX ) )
1472 nFrameType = XML_TEXT_FRAME_TEXTBOX;
1473 else if( IsXMLToken( rLocalName, XML_IMAGE ) )
1474 nFrameType = XML_TEXT_FRAME_GRAPHIC;
1475 else if( IsXMLToken( rLocalName, XML_OBJECT ) )
1476 nFrameType = XML_TEXT_FRAME_OBJECT;
1477 else if( IsXMLToken( rLocalName, XML_OBJECT_OLE ) )
1478 nFrameType = XML_TEXT_FRAME_OBJECT_OLE;
1479 else if( IsXMLToken( rLocalName, XML_APPLET) )
1480 nFrameType = XML_TEXT_FRAME_APPLET;
1481 else if( IsXMLToken( rLocalName, XML_PLUGIN ) )
1482 nFrameType = XML_TEXT_FRAME_PLUGIN;
1483 else if( IsXMLToken( rLocalName, XML_FLOATING_FRAME ) )
1484 nFrameType = XML_TEXT_FRAME_FLOATING_FRAME;
1486 if( USHRT_MAX != nFrameType )
1488 // Shapes in Writer cannot be named via context menu (#i51726#)
1489 if ( ( XML_TEXT_FRAME_TEXTBOX == nFrameType ||
1490 XML_TEXT_FRAME_GRAPHIC == nFrameType ) &&
1491 m_HasAutomaticStyleWithoutParentStyle )
1493 Reference < XShapes > xShapes;
1494 pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
1495 GetImport(), p_nPrefix, rLocalName, xAttrList, xShapes, m_xAttrList );
1497 else if( XML_TEXT_FRAME_PLUGIN == nFrameType )
1499 bool bMedia = false;
1501 // check, if we have a media object
1502 for( sal_Int16 n = 0, nAttrCount = ( xAttrList.is() ? xAttrList->getLength() : 0 ); n < nAttrCount; ++n )
1504 OUString aLocalName;
1505 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( n ), &aLocalName );
1507 if( nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( aLocalName, XML_MIME_TYPE ) )
1509 if( 0 == xAttrList->getValueByIndex( n ).compareToAscii( "application/vnd.sun.star.media" ) )
1510 bMedia = true;
1512 // leave this loop
1513 n = nAttrCount - 1;
1517 if( bMedia )
1519 Reference < XShapes > xShapes;
1520 pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
1521 GetImport(), p_nPrefix, rLocalName, xAttrList, xShapes, m_xAttrList );
1524 else if( XML_TEXT_FRAME_OBJECT == nFrameType ||
1525 XML_TEXT_FRAME_OBJECT_OLE == nFrameType )
1527 m_bSupportsReplacement = sal_True;
1529 else if(XML_TEXT_FRAME_GRAPHIC == nFrameType)
1531 setSupportsMultipleContents(IsXMLToken(rLocalName, XML_IMAGE));
1534 if( !pContext )
1537 pContext = new XMLTextFrameContext_Impl( GetImport(), p_nPrefix,
1538 rLocalName, xAttrList,
1539 m_eDefaultAnchorType,
1540 nFrameType,
1541 m_xAttrList );
1544 m_xImplContext = pContext;
1546 if(getSupportsMultipleContents() && XML_TEXT_FRAME_GRAPHIC == nFrameType)
1548 addContent(*m_xImplContext);
1553 else if(getSupportsMultipleContents() && XML_NAMESPACE_DRAW == p_nPrefix && IsXMLToken(rLocalName, XML_IMAGE))
1555 // read another image
1556 pContext = new XMLTextFrameContext_Impl(
1557 GetImport(), p_nPrefix, rLocalName, xAttrList,
1558 m_eDefaultAnchorType, XML_TEXT_FRAME_GRAPHIC, m_xAttrList);
1560 m_xImplContext = pContext;
1561 addContent(*m_xImplContext);
1563 else if( m_bSupportsReplacement && !m_xReplImplContext &&
1564 XML_NAMESPACE_DRAW == p_nPrefix &&
1565 IsXMLToken( rLocalName, XML_IMAGE ) )
1567 // read replacement image
1568 Reference < XPropertySet > xPropSet;
1569 if( CreateIfNotThere( xPropSet ) )
1571 pContext = new XMLReplacementImageContext( GetImport(),
1572 p_nPrefix, rLocalName, xAttrList, xPropSet );
1573 m_xReplImplContext = pContext;
1576 else if( m_xImplContext->ISA( XMLTextFrameContext_Impl ) )
1578 // the child is a writer frame
1579 if( XML_NAMESPACE_SVG == p_nPrefix )
1581 // Implement Title/Description Elements UI (#i73249#)
1582 const bool bOld = SvXMLImport::OOo_2x >= GetImport().getGeneratorVersion();
1583 if ( bOld )
1585 if ( IsXMLToken( rLocalName, XML_DESC ) )
1587 pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1588 p_nPrefix,
1589 rLocalName,
1590 m_sTitle );
1593 else
1595 if( IsXMLToken( rLocalName, XML_TITLE ) )
1597 pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1598 p_nPrefix,
1599 rLocalName,
1600 m_sTitle );
1602 else if ( IsXMLToken( rLocalName, XML_DESC ) )
1604 pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1605 p_nPrefix,
1606 rLocalName,
1607 m_sDesc );
1611 else if( XML_NAMESPACE_DRAW == p_nPrefix )
1613 Reference < XPropertySet > xPropSet;
1614 if( IsXMLToken( rLocalName, XML_CONTOUR_POLYGON ) )
1616 if( CreateIfNotThere( xPropSet ) )
1617 pContext = new XMLTextFrameContourContext_Impl( GetImport(), p_nPrefix, rLocalName,
1618 xAttrList, xPropSet, sal_False );
1620 else if( IsXMLToken( rLocalName, XML_CONTOUR_PATH ) )
1622 if( CreateIfNotThere( xPropSet ) )
1623 pContext = new XMLTextFrameContourContext_Impl( GetImport(), p_nPrefix, rLocalName,
1624 xAttrList, xPropSet, sal_True );
1626 else if( IsXMLToken( rLocalName, XML_IMAGE_MAP ) )
1628 if( CreateIfNotThere( xPropSet ) )
1629 pContext = new XMLImageMapContext( GetImport(), p_nPrefix, rLocalName, xPropSet );
1632 else if( (XML_NAMESPACE_OFFICE == p_nPrefix) && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
1634 // do we still have the frame object?
1635 Reference < XPropertySet > xPropSet;
1636 if( CreateIfNotThere( xPropSet ) )
1638 // is it an event supplier?
1639 Reference<XEventsSupplier> xEventsSupplier(xPropSet, UNO_QUERY);
1640 if (xEventsSupplier.is())
1642 // OK, we have the events, so create the context
1643 pContext = new XMLEventsImportContext(GetImport(), p_nPrefix,
1644 rLocalName, xEventsSupplier);
1649 else if( p_nPrefix == XML_NAMESPACE_SVG && // #i68101#
1650 (IsXMLToken( rLocalName, XML_TITLE ) || IsXMLToken( rLocalName, XML_DESC ) ) )
1652 pContext = m_xImplContext->CreateChildContext( p_nPrefix, rLocalName, xAttrList );
1654 else
1656 // the child is a drawing shape
1657 pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
1658 &m_xImplContext, p_nPrefix, rLocalName, xAttrList );
1661 if( !pContext )
1662 pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
1664 return pContext;
1667 void XMLTextFrameContext::SetHyperlink( const OUString& rHRef,
1668 const OUString& rName,
1669 const OUString& rTargetFrameName,
1670 sal_Bool bMap )
1672 OSL_ENSURE( !m_pHyperlink, "recursive SetHyperlink call" );
1673 delete m_pHyperlink;
1674 m_pHyperlink = new XMLTextFrameContextHyperlink_Impl(
1675 rHRef, rName, rTargetFrameName, bMap );
1678 TextContentAnchorType XMLTextFrameContext::GetAnchorType() const
1680 SvXMLImportContext *pContext = &m_xImplContext;
1681 XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1682 if( pImpl )
1683 return pImpl->GetAnchorType();
1684 else
1685 return m_eDefaultAnchorType;
1688 Reference < XTextContent > XMLTextFrameContext::GetTextContent() const
1690 Reference < XTextContent > xTxtCntnt;
1691 SvXMLImportContext *pContext = &m_xImplContext;
1692 XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1693 if( pImpl )
1694 xTxtCntnt.set( pImpl->GetPropSet(), UNO_QUERY );
1696 return xTxtCntnt;
1699 Reference < XShape > XMLTextFrameContext::GetShape() const
1701 Reference < XShape > xShape;
1702 SvXMLImportContext* pContext = &m_xImplContext;
1703 SvXMLShapeContext* pImpl = PTR_CAST( SvXMLShapeContext, pContext );
1704 if ( pImpl )
1706 xShape = pImpl->getShape();
1709 return xShape;
1712 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */