xref: /trunk/main/xmloff/source/text/XMLTextFrameContext.cxx (revision 74f1be36d980b87a5a095b012e7b3e9b4a8605eb)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <tools/debug.hxx>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/text/TextContentAnchorType.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/text/XTextFrame.hpp>
31 #include <com/sun/star/container/XNamed.hpp>
32 #include <com/sun/star/text/SizeType.hpp>
33 #include <com/sun/star/drawing/XShape.hpp>
34 #include <com/sun/star/document/XEventsSupplier.hpp>
35 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
36 #include <com/sun/star/io/XOutputStream.hpp>
37 #include <com/sun/star/text/HoriOrientation.hpp>
38 #include <com/sun/star/text/VertOrientation.hpp>
39 #include <xmloff/xmlimp.hxx>
40 #include <xmloff/xmltoken.hxx>
41 #include "xmloff/xmlnmspe.hxx"
42 #include <xmloff/nmspmap.hxx>
43 #include <xmloff/xmluconv.hxx>
44 #include "XMLAnchorTypePropHdl.hxx"
45 #include "XMLEmbeddedObjectImportContext.hxx"
46 #include <xmloff/XMLBase64ImportContext.hxx>
47 #include "XMLReplacementImageContext.hxx"
48 #include <xmloff/prstylei.hxx>
49 #include "xmloff/i18nmap.hxx"
50 #include "xexptran.hxx"
51 #include <xmloff/shapeimport.hxx>
52 #include <xmloff/XMLEventsImportContext.hxx>
53 #include "XMLImageMapContext.hxx"
54 #include "XMLTextFrameContext.hxx"
55 
56 #include "XMLTextListBlockContext.hxx"
57 #include "XMLTextListItemContext.hxx"
58 #include <xmloff/attrlist.hxx>
59 #include <comphelper/stl_types.hxx>
60 
61 #include <map>
62 
63 
64 using ::rtl::OUString;
65 using ::rtl::OUStringBuffer;
66 
67 using namespace ::com::sun::star;
68 using namespace ::com::sun::star::uno;
69 using namespace ::com::sun::star::text;
70 using namespace ::com::sun::star::xml::sax;
71 using namespace ::com::sun::star::beans;
72 using namespace ::com::sun::star::lang;
73 using namespace ::com::sun::star::container;
74 using namespace ::com::sun::star::drawing;
75 using namespace ::com::sun::star::document;
76 using namespace ::xmloff::token;
77 using ::com::sun::star::document::XEventsSupplier;
78 
79 #define XML_TEXT_FRAME_TEXTBOX 1
80 #define XML_TEXT_FRAME_GRAPHIC 2
81 #define XML_TEXT_FRAME_OBJECT 3
82 #define XML_TEXT_FRAME_OBJECT_OLE 4
83 #define XML_TEXT_FRAME_APPLET 5
84 #define XML_TEXT_FRAME_PLUGIN 6
85 #define XML_TEXT_FRAME_FLOATING_FRAME 7
86 
87 typedef ::std::map < const ::rtl::OUString, ::rtl::OUString, ::comphelper::UStringLess> ParamMap;
88 
89 class XMLTextFrameContextHyperlink_Impl
90 {
91     OUString sHRef;
92     OUString sName;
93     OUString sTargetFrameName;
94     sal_Bool bMap;
95 
96 public:
97 
98     inline XMLTextFrameContextHyperlink_Impl( const OUString& rHRef,
99                        const OUString& rName,
100                        const OUString& rTargetFrameName,
101                        sal_Bool bMap );
102 
103     const OUString& GetHRef() const { return sHRef; }
104     const OUString& GetName() const { return sName; }
105     const OUString& GetTargetFrameName() const { return sTargetFrameName; }
106     sal_Bool GetMap() const { return bMap; }
107 };
108 
109 inline XMLTextFrameContextHyperlink_Impl::XMLTextFrameContextHyperlink_Impl(
110     const OUString& rHRef, const OUString& rName,
111     const OUString& rTargetFrameName, sal_Bool bM ) :
112     sHRef( rHRef ),
113     sName( rName ),
114     sTargetFrameName( rTargetFrameName ),
115     bMap( bM )
116 {
117 }
118 
119 // --> OD 2009-07-22 #i73249#
120 class XMLTextFrameTitleOrDescContext_Impl : public SvXMLImportContext
121 {
122     OUString&   mrTitleOrDesc;
123 
124 public:
125 
126     TYPEINFO();
127 
128     XMLTextFrameTitleOrDescContext_Impl( SvXMLImport& rImport,
129                                          sal_uInt16 nPrfx,
130                                          const ::rtl::OUString& rLName,
131                                          OUString& rTitleOrDesc );
132     virtual ~XMLTextFrameTitleOrDescContext_Impl();
133 
134     virtual void Characters( const OUString& rText );
135 };
136 
137 TYPEINIT1( XMLTextFrameTitleOrDescContext_Impl, SvXMLImportContext );
138 
139 XMLTextFrameTitleOrDescContext_Impl::XMLTextFrameTitleOrDescContext_Impl(
140         SvXMLImport& rImport,
141         sal_uInt16 nPrfx,
142         const OUString& rLName,
143         OUString& rTitleOrDesc )
144     : SvXMLImportContext( rImport, nPrfx, rLName )
145     , mrTitleOrDesc( rTitleOrDesc )
146 {
147 }
148 
149 XMLTextFrameTitleOrDescContext_Impl::~XMLTextFrameTitleOrDescContext_Impl()
150 {
151 }
152 
153 void XMLTextFrameTitleOrDescContext_Impl::Characters( const OUString& rText )
154 {
155     mrTitleOrDesc += rText;
156 }
157 // <--
158 
159 // ------------------------------------------------------------------------
160 
161 class XMLTextFrameParam_Impl : public SvXMLImportContext
162 {
163 public:
164 
165     TYPEINFO();
166 
167     XMLTextFrameParam_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
168                                   const ::rtl::OUString& rLName,
169             const ::com::sun::star::uno::Reference<
170                 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
171             sal_uInt16 nType,
172             ParamMap &rParamMap);
173     virtual ~XMLTextFrameParam_Impl();
174 };
175 
176 TYPEINIT1( XMLTextFrameParam_Impl, SvXMLImportContext );
177 
178 XMLTextFrameParam_Impl::~XMLTextFrameParam_Impl()
179 {
180 }
181 
182 XMLTextFrameParam_Impl::XMLTextFrameParam_Impl(
183         SvXMLImport& rImport, sal_uInt16 nPrfx,
184         const ::rtl::OUString& rLName,
185         const ::com::sun::star::uno::Reference<
186                 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
187         sal_uInt16 /*nType*/,
188         ParamMap &rParamMap):
189     SvXMLImportContext( rImport, nPrfx, rLName )
190 {
191     OUString sName, sValue;
192     sal_Bool bFoundValue = sal_False; // to allow empty values
193     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
194     for( sal_Int16 i=0; i < nAttrCount; i++ )
195     {
196         const OUString& rAttrName = xAttrList->getNameByIndex( i );
197         const OUString& rValue = xAttrList->getValueByIndex( i );
198 
199         OUString aLocalName;
200         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
201         if ( XML_NAMESPACE_DRAW == nPrefix )
202         {
203             if( IsXMLToken(aLocalName, XML_VALUE) )
204             {
205                 sValue = rValue;
206                 bFoundValue=sal_True;
207             }
208             else if( IsXMLToken(aLocalName, XML_NAME) )
209             {
210                 sName = rValue;
211             }
212         }
213     }
214     if (sName.getLength() && bFoundValue )
215         rParamMap[sName] = sValue;
216 }
217 class XMLTextFrameContourContext_Impl : public SvXMLImportContext
218 {
219     Reference < XPropertySet > xPropSet;
220 
221 public:
222 
223     TYPEINFO();
224 
225     XMLTextFrameContourContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
226                                   const ::rtl::OUString& rLName,
227             const ::com::sun::star::uno::Reference<
228                 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
229             const Reference < XPropertySet >& rPropSet,
230             sal_Bool bPath );
231     virtual ~XMLTextFrameContourContext_Impl();
232 };
233 
234 TYPEINIT1( XMLTextFrameContourContext_Impl, SvXMLImportContext );
235 
236 XMLTextFrameContourContext_Impl::XMLTextFrameContourContext_Impl(
237         SvXMLImport& rImport,
238         sal_uInt16 nPrfx, const OUString& rLName,
239         const Reference< XAttributeList > & xAttrList,
240         const Reference < XPropertySet >& rPropSet,
241         sal_Bool bPath ) :
242     SvXMLImportContext( rImport, nPrfx, rLName ),
243     xPropSet( rPropSet )
244 {
245     OUString sD, sPoints, sViewBox;
246     sal_Bool bPixelWidth = sal_False, bPixelHeight = sal_False;
247     sal_Bool bAuto = sal_False;
248     sal_Int32 nWidth = 0;
249     sal_Int32 nHeight = 0;
250 
251     const SvXMLTokenMap& rTokenMap =
252         GetImport().GetTextImport()->GetTextContourAttrTokenMap();
253 
254     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
255     for( sal_Int16 i=0; i < nAttrCount; i++ )
256     {
257         const OUString& rAttrName = xAttrList->getNameByIndex( i );
258         const OUString& rValue = xAttrList->getValueByIndex( i );
259 
260         OUString aLocalName;
261         sal_uInt16 nPrefix =
262             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
263                                                             &aLocalName );
264         switch( rTokenMap.Get( nPrefix, aLocalName ) )
265         {
266         case XML_TOK_TEXT_CONTOUR_VIEWBOX:
267             sViewBox = rValue;
268             break;
269         case XML_TOK_TEXT_CONTOUR_D:
270             if( bPath )
271                 sD = rValue;
272             break;
273         case XML_TOK_TEXT_CONTOUR_POINTS:
274             if( !bPath )
275                 sPoints = rValue;
276             break;
277         case XML_TOK_TEXT_CONTOUR_WIDTH:
278             if( GetImport().GetMM100UnitConverter().convertMeasurePx( nWidth,
279                                                                       rValue) )
280                 bPixelWidth = sal_True;
281             else
282                 GetImport().GetMM100UnitConverter().convertMeasure( nWidth,
283                                                                 rValue);
284             break;
285         case XML_TOK_TEXT_CONTOUR_HEIGHT:
286             if( GetImport().GetMM100UnitConverter().convertMeasurePx( nHeight,
287                                                                 rValue) )
288                 bPixelHeight = sal_True;
289             else
290                 GetImport().GetMM100UnitConverter().convertMeasure( nHeight,
291                                                                     rValue);
292             break;
293         case XML_TOK_TEXT_CONTOUR_AUTO:
294             bAuto = IsXMLToken(rValue, XML_TRUE);
295             break;
296         }
297     }
298 
299     OUString sContourPolyPolygon(
300             RTL_CONSTASCII_USTRINGPARAM("ContourPolyPolygon") );
301     Reference < XPropertySetInfo > xPropSetInfo =
302         rPropSet->getPropertySetInfo();
303     if( xPropSetInfo->hasPropertyByName(
304                                                     sContourPolyPolygon ) &&
305         nWidth > 0 && nHeight > 0 && bPixelWidth == bPixelHeight &&
306         (bPath ? sD : sPoints).getLength() )
307     {
308         awt::Point aPoint( 0,  0 );
309         awt::Size aSize( nWidth, nHeight );
310         SdXMLImExViewBox aViewBox( sViewBox,
311                                    GetImport().GetMM100UnitConverter());
312         Any aAny;
313         if( bPath )
314         {
315             SdXMLImExSvgDElement aPoints( sD, aViewBox, aPoint, aSize,
316                                           GetImport().GetMM100UnitConverter() );
317             aAny <<= aPoints.GetPointSequenceSequence();
318         }
319         else
320         {
321             SdXMLImExPointsElement aPoints( sPoints, aViewBox, aPoint, aSize,
322                                         GetImport().GetMM100UnitConverter() );
323             aAny <<= aPoints.GetPointSequenceSequence();
324         }
325 
326         OUString sIsPixelContour(
327                 RTL_CONSTASCII_USTRINGPARAM("IsPixelContour") );
328         xPropSet->setPropertyValue( sContourPolyPolygon, aAny );
329 
330         if( xPropSetInfo->hasPropertyByName( sIsPixelContour ) )
331         {
332             aAny.setValue( &bPixelWidth, ::getBooleanCppuType() );
333             xPropSet->setPropertyValue( sIsPixelContour, aAny );
334         }
335 
336         OUString sIsAutomaticContour(
337                 RTL_CONSTASCII_USTRINGPARAM("IsAutomaticContour") );
338         if( xPropSetInfo->hasPropertyByName( sIsAutomaticContour ) )
339         {
340             aAny.setValue( &bAuto, ::getBooleanCppuType() );
341             xPropSet->setPropertyValue( sIsAutomaticContour, aAny );
342         }
343     }
344 }
345 
346 XMLTextFrameContourContext_Impl::~XMLTextFrameContourContext_Impl()
347 {
348 }
349 
350 // ------------------------------------------------------------------------
351 
352 class XMLTextFrameContext_Impl : public SvXMLImportContext
353 {
354     ::com::sun::star::uno::Reference <
355         ::com::sun::star::text::XTextCursor > xOldTextCursor;
356     ::com::sun::star::uno::Reference <
357         ::com::sun::star::beans::XPropertySet > xPropSet;
358     ::com::sun::star::uno::Reference <
359         ::com::sun::star::io::XOutputStream > xBase64Stream;
360 
361     /// old list item and block (#89891#)
362     bool mbListContextPushed;
363 
364     const ::rtl::OUString sWidth;
365     const ::rtl::OUString sWidthType;
366     const ::rtl::OUString sRelativeWidth;
367     const ::rtl::OUString sHeight;
368     const ::rtl::OUString sRelativeHeight;
369     const ::rtl::OUString sSizeType;
370     const ::rtl::OUString sIsSyncWidthToHeight;
371     const ::rtl::OUString sIsSyncHeightToWidth;
372     const ::rtl::OUString sHoriOrient;
373     const ::rtl::OUString sHoriOrientPosition;
374     const ::rtl::OUString sVertOrient;
375     const ::rtl::OUString sVertOrientPosition;
376     const ::rtl::OUString sChainNextName;
377     const ::rtl::OUString sAnchorType;
378     const ::rtl::OUString sAnchorPageNo;
379     const ::rtl::OUString sGraphicURL;
380     const ::rtl::OUString sGraphicFilter;
381     // --> OD 2009-07-22 #i73249#
382 //    const ::rtl::OUString sAlternativeText;
383     const ::rtl::OUString sTitle;
384     const ::rtl::OUString sDescription;
385     // <--
386     const ::rtl::OUString sFrameStyleName;
387     const ::rtl::OUString sGraphicRotation;
388     const ::rtl::OUString sTextBoxServiceName;
389     const ::rtl::OUString sGraphicServiceName;
390 
391     ::rtl::OUString sName;
392     ::rtl::OUString sStyleName;
393     ::rtl::OUString sNextName;
394     ::rtl::OUString sHRef;
395     ::rtl::OUString sFilterName;
396     ::rtl::OUString sCode;
397     ::rtl::OUString sObject;
398     ::rtl::OUString sArchive;
399     ::rtl::OUString sMimeType;
400     ::rtl::OUString sFrameName;
401     ::rtl::OUString sAppletName;
402     ::rtl::OUString sFilterService;
403     ::rtl::OUString sBase64CharsLeft;
404     ::rtl::OUString sTblName;
405 
406     ParamMap aParamMap;
407 
408     sal_Int32   nX;
409     sal_Int32   nY;
410     sal_Int32   nWidth;
411     sal_Int32   nHeight;
412     sal_Int32   nZIndex;
413     sal_Int16   nPage;
414     sal_Int16   nRotation;
415     sal_Int16   nRelWidth;
416     sal_Int16   nRelHeight;
417 
418     sal_uInt16 nType;
419     ::com::sun::star::text::TextContentAnchorType   eAnchorType;
420 
421     sal_Bool    bMayScript : 1;
422     sal_Bool    bMinWidth : 1;
423     sal_Bool    bMinHeight : 1;
424     sal_Bool    bSyncWidth : 1;
425     sal_Bool    bSyncHeight : 1;
426     sal_Bool    bCreateFailed : 1;
427     sal_Bool    bOwnBase64Stream : 1;
428 
429     void Create( sal_Bool bHRefOrBase64 );
430 
431 public:
432 
433     TYPEINFO();
434 
435     sal_Bool CreateIfNotThere();
436 
437     XMLTextFrameContext_Impl( SvXMLImport& rImport,
438             sal_uInt16 nPrfx,
439             const ::rtl::OUString& rLName,
440             const ::com::sun::star::uno::Reference<
441                 ::com::sun::star::xml::sax::XAttributeList > & rAttrList,
442             ::com::sun::star::text::TextContentAnchorType eAnchorType,
443             sal_uInt16 nType,
444             const ::com::sun::star::uno::Reference<
445                 ::com::sun::star::xml::sax::XAttributeList > & rFrameAttrList );
446     virtual ~XMLTextFrameContext_Impl();
447 
448     virtual void EndElement();
449 
450     virtual void Characters( const ::rtl::OUString& rChars );
451 
452     SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
453                 const ::rtl::OUString& rLocalName,
454                 const ::com::sun::star::uno::Reference<
455                     ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
456 
457     void SetHyperlink( const ::rtl::OUString& rHRef,
458                        const ::rtl::OUString& rName,
459                        const ::rtl::OUString& rTargetFrameName,
460                        sal_Bool bMap );
461     // --> OD 2009-07-22 #i73249#
462     void SetTitle( const ::rtl::OUString& rTitle );
463     // <--
464     void SetDesc( const ::rtl::OUString& rDesc );
465 
466     ::com::sun::star::text::TextContentAnchorType GetAnchorType() const { return eAnchorType; }
467 
468     const ::com::sun::star::uno::Reference <
469         ::com::sun::star::beans::XPropertySet >& GetPropSet() { return xPropSet; }
470 };
471 
472 TYPEINIT1( XMLTextFrameContext_Impl, SvXMLImportContext );
473 
474 void XMLTextFrameContext_Impl::Create( sal_Bool /*bHRefOrBase64*/ )
475 {
476     UniReference < XMLTextImportHelper > xTextImportHelper =
477         GetImport().GetTextImport();
478 
479     switch ( nType)
480     {
481         case XML_TEXT_FRAME_OBJECT:
482         case XML_TEXT_FRAME_OBJECT_OLE:
483             if( xBase64Stream.is() )
484             {
485                 OUString sURL( GetImport().ResolveEmbeddedObjectURLFromBase64() );
486                 if( sURL.getLength() )
487                     xPropSet = GetImport().GetTextImport()
488                             ->createAndInsertOLEObject( GetImport(), sURL,
489                                                         sStyleName,
490                                                         sTblName,
491                                                         nWidth, nHeight );
492             }
493             else if( sHRef.getLength() )
494             {
495                 OUString sURL( GetImport().ResolveEmbeddedObjectURL( sHRef,
496                                                                 OUString() ) );
497 
498                 if( GetImport().IsPackageURL( sHRef ) )
499                 {
500                     xPropSet = GetImport().GetTextImport()
501                             ->createAndInsertOLEObject( GetImport(), sURL,
502                                                         sStyleName,
503                                                         sTblName,
504                                                         nWidth, nHeight );
505                 }
506                 else
507                 {
508                     // it should be an own OOo link that has no storage persistance
509                     xPropSet = GetImport().GetTextImport()
510                             ->createAndInsertOOoLink( GetImport(),
511                                                         sURL,
512                                                         sStyleName,
513                                                         sTblName,
514                                                         nWidth, nHeight );
515                 }
516             }
517             else
518             {
519                 OUString sURL( RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.ServiceName:") );
520                 sURL += sFilterService;
521                 xPropSet = GetImport().GetTextImport()
522                             ->createAndInsertOLEObject( GetImport(), sURL,
523                                                         sStyleName,
524                                                         sTblName,
525                                                         nWidth, nHeight );
526 
527             }
528             break;
529         case XML_TEXT_FRAME_APPLET:
530         {
531             xPropSet = GetImport().GetTextImport()
532                             ->createAndInsertApplet( sAppletName, sCode,
533                                                      bMayScript, sHRef,
534                                                      nWidth, nHeight);
535             break;
536         }
537         case XML_TEXT_FRAME_PLUGIN:
538         {
539             if(sHRef.getLength())
540                 GetImport().GetAbsoluteReference(sHRef);
541             xPropSet = GetImport().GetTextImport()
542                             ->createAndInsertPlugin( sMimeType, sHRef,
543                                                      nWidth, nHeight);
544 
545             break;
546         }
547         case XML_TEXT_FRAME_FLOATING_FRAME:
548         {
549             xPropSet = GetImport().GetTextImport()
550                             ->createAndInsertFloatingFrame( sFrameName, sHRef,
551                                                             sStyleName,
552                                                             nWidth, nHeight);
553             break;
554         }
555         default:
556         {
557             Reference<XMultiServiceFactory> xFactory( GetImport().GetModel(),
558                                                       UNO_QUERY );
559             if( xFactory.is() )
560             {
561                 OUString sServiceName;
562                 switch( nType )
563                 {
564                     case XML_TEXT_FRAME_TEXTBOX: sServiceName = sTextBoxServiceName; break;
565                     case XML_TEXT_FRAME_GRAPHIC: sServiceName = sGraphicServiceName; break;
566                 }
567                 Reference<XInterface> xIfc = xFactory->createInstance( sServiceName );
568                 DBG_ASSERT( xIfc.is(), "couldn't create frame" );
569                 if( xIfc.is() )
570                     xPropSet = Reference < XPropertySet >( xIfc, UNO_QUERY );
571             }
572         }
573     }
574 
575     if( !xPropSet.is() )
576     {
577         bCreateFailed = sal_True;
578         return;
579     }
580 
581     Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
582 
583     // set name
584     Reference < XNamed > xNamed( xPropSet, UNO_QUERY );
585     if( xNamed.is() )
586     {
587         OUString sOrigName( xNamed->getName() );
588         if( !sOrigName.getLength() ||
589             (sName.getLength() && sOrigName != sName) )
590         {
591             OUString sOldName( sName );
592             sal_Int32 i = 0;
593             while( xTextImportHelper->HasFrameByName( sName ) )
594             {
595                 sName = sOldName;
596                 sName += OUString::valueOf( ++i );
597             }
598             xNamed->setName( sName );
599             if( sName != sOldName )
600                 xTextImportHelper->GetRenameMap().Add( XML_TEXT_RENAME_TYPE_FRAME,
601                                              sOldName, sName );
602         }
603     }
604 
605     // frame style
606     XMLPropStyleContext *pStyle = 0;
607     if( sStyleName.getLength() )
608     {
609         pStyle = xTextImportHelper->FindAutoFrameStyle( sStyleName );
610         if( pStyle )
611             sStyleName = pStyle->GetParentName();
612     }
613 
614     Any aAny;
615     if( sStyleName.getLength() )
616     {
617         OUString sDisplayStyleName( GetImport().GetStyleDisplayName(
618                             XML_STYLE_FAMILY_SD_GRAPHICS_ID, sStyleName ) );
619         const Reference < XNameContainer > & rStyles =
620             xTextImportHelper->GetFrameStyles();
621         if( rStyles.is() &&
622             rStyles->hasByName( sDisplayStyleName ) )
623         {
624             aAny <<= sDisplayStyleName;
625             xPropSet->setPropertyValue( sFrameStyleName, aAny );
626         }
627     }
628 
629     // anchor type (must be set before any other properties, because
630     // otherwise some orientations cannot be set or will be changed
631     // afterwards)
632     aAny <<= eAnchorType;
633     xPropSet->setPropertyValue( sAnchorType, aAny );
634 
635     // hard properties
636     if( pStyle )
637         pStyle->FillPropertySet( xPropSet );
638 
639 
640     // x and y
641     sal_Int16 nHoriOrient =  HoriOrientation::NONE;
642     aAny = xPropSet->getPropertyValue( sHoriOrient );
643     aAny >>= nHoriOrient;
644     if( HoriOrientation::NONE == nHoriOrient )
645     {
646         aAny <<= nX;
647         xPropSet->setPropertyValue( sHoriOrientPosition, aAny );
648     }
649 
650     sal_Int16 nVertOrient =  VertOrientation::NONE;
651     aAny = xPropSet->getPropertyValue( sVertOrient );
652     aAny >>= nVertOrient;
653     if( VertOrientation::NONE == nVertOrient )
654     {
655         aAny <<= nY;
656         xPropSet->setPropertyValue( sVertOrientPosition, aAny );
657     }
658 
659     // width
660     if( nWidth > 0 )
661     {
662         aAny <<= nWidth;
663         xPropSet->setPropertyValue( sWidth, aAny );
664     }
665     if( nRelWidth > 0 || nWidth > 0 )
666     {
667         aAny <<= nRelWidth;
668         xPropSet->setPropertyValue( sRelativeWidth, aAny );
669     }
670     if( bSyncWidth || nWidth > 0 )
671     {
672         sal_Bool bTmp = bSyncWidth;
673         aAny.setValue( &bTmp, ::getBooleanCppuType() );
674         xPropSet->setPropertyValue( sIsSyncWidthToHeight, aAny );
675     }
676     if( xPropSetInfo->hasPropertyByName( sWidthType ) &&
677         (bMinWidth || nWidth > 0 || nRelWidth > 0 ) )
678     {
679         sal_Int16 nSizeType =
680             (bMinWidth && XML_TEXT_FRAME_TEXTBOX == nType) ? SizeType::MIN
681                                                            : SizeType::FIX;
682         aAny <<= nSizeType;
683         xPropSet->setPropertyValue( sWidthType, aAny );
684     }
685 
686     if( nHeight > 0 )
687     {
688         aAny <<= nHeight;
689         xPropSet->setPropertyValue( sHeight, aAny );
690     }
691     if( nRelHeight > 0 || nHeight > 0 )
692     {
693         aAny <<= nRelHeight;
694         xPropSet->setPropertyValue( sRelativeHeight, aAny );
695     }
696     if( bSyncHeight || nHeight > 0 )
697     {
698         sal_Bool bTmp = bSyncHeight;
699         aAny.setValue( &bTmp, ::getBooleanCppuType() );
700         xPropSet->setPropertyValue( sIsSyncHeightToWidth, aAny );
701     }
702     if( xPropSetInfo->hasPropertyByName( sSizeType ) &&
703         (bMinHeight || nHeight > 0 || nRelHeight > 0 ) )
704     {
705         sal_Int16 nSizeType =
706             (bMinHeight && XML_TEXT_FRAME_TEXTBOX == nType) ? SizeType::MIN
707                                                             : SizeType::FIX;
708         aAny <<= nSizeType;
709         xPropSet->setPropertyValue( sSizeType, aAny );
710     }
711 
712     if( XML_TEXT_FRAME_GRAPHIC == nType )
713     {
714         // URL
715         OSL_ENSURE( sHRef.getLength() > 0 || xBase64Stream.is(),
716                     "neither URL nor base64 image data given" );
717         UniReference < XMLTextImportHelper > xTxtImport =
718             GetImport().GetTextImport();
719         if( sHRef.getLength() )
720         {
721             sal_Bool bForceLoad = xTxtImport->IsInsertMode() ||
722                                   xTxtImport->IsBlockMode() ||
723                                   xTxtImport->IsStylesOnlyMode() ||
724                                   xTxtImport->IsOrganizerMode();
725             sHRef = GetImport().ResolveGraphicObjectURL( sHRef, !bForceLoad );
726         }
727         else if( xBase64Stream.is() )
728         {
729             sHRef = GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream );
730             xBase64Stream = 0;
731         }
732         aAny <<= sHRef;
733         xPropSet->setPropertyValue( sGraphicURL, aAny );
734 
735         // filter name
736         aAny <<=sFilterName;
737         xPropSet->setPropertyValue( sGraphicFilter, aAny );
738 
739         // rotation
740         aAny <<= nRotation;
741         xPropSet->setPropertyValue( sGraphicRotation, aAny );
742     }
743 
744     // page number (must be set after the frame is inserted, because it
745     // will be overwritten then inserting the frame.
746     if( TextContentAnchorType_AT_PAGE == eAnchorType && nPage > 0 )
747     {
748         aAny <<= nPage;
749         xPropSet->setPropertyValue( sAnchorPageNo, aAny );
750     }
751 
752     if( XML_TEXT_FRAME_OBJECT != nType  &&
753         XML_TEXT_FRAME_OBJECT_OLE != nType  &&
754         XML_TEXT_FRAME_APPLET != nType &&
755         XML_TEXT_FRAME_PLUGIN!= nType &&
756         XML_TEXT_FRAME_FLOATING_FRAME != nType)
757     {
758         Reference < XTextContent > xTxtCntnt( xPropSet, UNO_QUERY );
759         xTextImportHelper->InsertTextContent( xTxtCntnt );
760     }
761 
762     Reference < XShape > xShape( xPropSet, UNO_QUERY );
763 
764     // #107848#
765     // Make adding the shepe to Z-Ordering dependent from if we are
766     // inside a inside_deleted_section (redlining). That is necessary
767     // since the shape will be removed again later. It would lead to
768     // errors if it would stay inside the Z-Ordering. Thus, the
769     // easiest way to solve that conflict is to not add it here.
770     if(!GetImport().HasTextImport()
771         || !GetImport().GetTextImport()->IsInsideDeleteContext())
772     {
773         GetImport().GetShapeImport()->shapeWithZIndexAdded( xShape, nZIndex );
774     }
775 
776     if( XML_TEXT_FRAME_TEXTBOX == nType )
777     {
778         xTextImportHelper->ConnectFrameChains( sName, sNextName, xPropSet );
779         Reference < XTextFrame > xTxtFrame( xPropSet, UNO_QUERY );
780         Reference < XText > xTxt = xTxtFrame->getText();
781         xOldTextCursor = xTextImportHelper->GetCursor();
782         xTextImportHelper->SetCursor( xTxt->createTextCursor() );
783 
784         // remember old list item and block (#89892#) and reset them
785         // for the text frame
786         xTextImportHelper->PushListContext();
787         mbListContextPushed = true;
788     }
789 }
790 
791 sal_Bool XMLTextFrameContext_Impl::CreateIfNotThere()
792 {
793     if( !xPropSet.is() &&
794         ( XML_TEXT_FRAME_OBJECT_OLE == nType ||
795           XML_TEXT_FRAME_GRAPHIC == nType ) &&
796         xBase64Stream.is() && !bCreateFailed )
797     {
798         if( bOwnBase64Stream )
799             xBase64Stream->closeOutput();
800         Create( sal_True );
801     }
802 
803     return xPropSet.is();
804 }
805 
806 XMLTextFrameContext_Impl::XMLTextFrameContext_Impl(
807         SvXMLImport& rImport,
808         sal_uInt16 nPrfx, const OUString& rLName,
809         const Reference< XAttributeList > & rAttrList,
810         TextContentAnchorType eATyp,
811         sal_uInt16 nNewType,
812         const Reference< XAttributeList > & rFrameAttrList )
813 :   SvXMLImportContext( rImport, nPrfx, rLName )
814 ,   mbListContextPushed( false )
815 ,   sWidth(RTL_CONSTASCII_USTRINGPARAM("Width"))
816 ,   sWidthType(RTL_CONSTASCII_USTRINGPARAM("WidthType"))
817 ,   sRelativeWidth(RTL_CONSTASCII_USTRINGPARAM("RelativeWidth"))
818 ,   sHeight(RTL_CONSTASCII_USTRINGPARAM("Height"))
819 ,   sRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("RelativeHeight"))
820 ,   sSizeType(RTL_CONSTASCII_USTRINGPARAM("SizeType"))
821 ,   sIsSyncWidthToHeight(RTL_CONSTASCII_USTRINGPARAM("IsSyncWidthToHeight"))
822 ,   sIsSyncHeightToWidth(RTL_CONSTASCII_USTRINGPARAM("IsSyncHeightToWidth"))
823 ,   sHoriOrient(RTL_CONSTASCII_USTRINGPARAM("HoriOrient"))
824 ,   sHoriOrientPosition(RTL_CONSTASCII_USTRINGPARAM("HoriOrientPosition"))
825 ,   sVertOrient(RTL_CONSTASCII_USTRINGPARAM("VertOrient"))
826 ,   sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition"))
827 ,   sChainNextName(RTL_CONSTASCII_USTRINGPARAM("ChainNextName"))
828 ,   sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType"))
829 ,   sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo"))
830 ,   sGraphicURL(RTL_CONSTASCII_USTRINGPARAM("GraphicURL"))
831 ,   sGraphicFilter(RTL_CONSTASCII_USTRINGPARAM("GraphicFilter"))
832 // --> OD 2009-07-22 #i73249#
833 //,   sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText"))
834 ,   sTitle(RTL_CONSTASCII_USTRINGPARAM("Title"))
835 ,   sDescription(RTL_CONSTASCII_USTRINGPARAM("Description"))
836 // <--
837 ,   sFrameStyleName(RTL_CONSTASCII_USTRINGPARAM("FrameStyleName"))
838 ,   sGraphicRotation(RTL_CONSTASCII_USTRINGPARAM("GraphicRotation"))
839 ,   sTextBoxServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFrame"))
840 ,   sGraphicServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.GraphicObject"))
841 ,   nType( nNewType )
842 ,   eAnchorType( eATyp )
843 {
844     nX = 0;
845     nY = 0;
846     nWidth = 0;
847     nHeight = 0;
848     nZIndex = -1;
849     nPage = 0;
850     nRotation = 0;
851     nRelWidth = 0;
852     nRelHeight = 0;
853     bMayScript = sal_False;
854 
855     bMinHeight = sal_False;
856     bMinWidth = sal_False;
857     bSyncWidth = sal_False;
858     bSyncHeight = sal_False;
859     bCreateFailed = sal_False;
860     bOwnBase64Stream = sal_False;
861 
862     UniReference < XMLTextImportHelper > xTxtImport =
863         GetImport().GetTextImport();
864     const SvXMLTokenMap& rTokenMap =
865         xTxtImport->GetTextFrameAttrTokenMap();
866 
867     sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
868     sal_Int16 nTotalAttrCount = nAttrCount + (rFrameAttrList.is() ? rFrameAttrList->getLength() : 0);
869     for( sal_Int16 i=0; i < nTotalAttrCount; i++ )
870     {
871         const OUString& rAttrName =
872             i < nAttrCount ? rAttrList->getNameByIndex( i ) : rFrameAttrList->getNameByIndex( i-nAttrCount );
873         const OUString& rValue =
874             i < nAttrCount ? rAttrList->getValueByIndex( i ): rFrameAttrList->getValueByIndex( i-nAttrCount );
875 
876         OUString aLocalName;
877         sal_uInt16 nPrefix =
878             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
879                                                             &aLocalName );
880         switch( rTokenMap.Get( nPrefix, aLocalName ) )
881         {
882         case XML_TOK_TEXT_FRAME_STYLE_NAME:
883             sStyleName = rValue;
884             break;
885         case XML_TOK_TEXT_FRAME_NAME:
886             sName = rValue;
887             break;
888         case XML_TOK_TEXT_FRAME_FRAME_NAME:
889             sFrameName = rValue;
890             break;
891         case XML_TOK_TEXT_FRAME_APPLET_NAME:
892             sAppletName = rValue;
893             break;
894         case XML_TOK_TEXT_FRAME_ANCHOR_TYPE:
895             if( TextContentAnchorType_AT_PARAGRAPH == eAnchorType ||
896                 TextContentAnchorType_AT_CHARACTER == eAnchorType ||
897                 TextContentAnchorType_AS_CHARACTER == eAnchorType )
898             {
899 
900                 TextContentAnchorType eNew;
901                 if( XMLAnchorTypePropHdl::convert( rValue, eNew ) &&
902                     ( TextContentAnchorType_AT_PARAGRAPH == eNew ||
903                       TextContentAnchorType_AT_CHARACTER == eNew ||
904                       TextContentAnchorType_AS_CHARACTER == eNew ||
905                       TextContentAnchorType_AT_PAGE == eNew) )
906                     eAnchorType = eNew;
907             }
908             break;
909         case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER:
910             {
911                 sal_Int32 nTmp;
912                 if( GetImport().GetMM100UnitConverter().
913                                 convertNumber( nTmp, rValue, 1, SHRT_MAX ) )
914                     nPage = (sal_Int16)nTmp;
915             }
916             break;
917         case XML_TOK_TEXT_FRAME_X:
918             GetImport().GetMM100UnitConverter().convertMeasure( nX, rValue );
919             break;
920         case XML_TOK_TEXT_FRAME_Y:
921             GetImport().GetMM100UnitConverter().convertMeasure( nY, rValue );
922             break;
923         case XML_TOK_TEXT_FRAME_WIDTH:
924             // relative widths are obsolete since SRC617. Remove them some day!
925             if( rValue.indexOf( '%' ) != -1 )
926             {
927                 sal_Int32 nTmp;
928                 GetImport().GetMM100UnitConverter().convertPercent( nTmp,
929                                                                     rValue );
930                 nRelWidth = (sal_Int16)nTmp;
931             }
932             else
933             {
934                 GetImport().GetMM100UnitConverter().convertMeasure( nWidth,
935                                                                     rValue, 0 );
936             }
937             break;
938         case XML_TOK_TEXT_FRAME_REL_WIDTH:
939             if( IsXMLToken(rValue, XML_SCALE) )
940             {
941                 bSyncWidth = sal_True;
942             }
943             else
944             {
945                 sal_Int32 nTmp;
946                 if( GetImport().GetMM100UnitConverter().
947                         convertPercent( nTmp, rValue ) )
948                     nRelWidth = (sal_Int16)nTmp;
949             }
950             break;
951         case XML_TOK_TEXT_FRAME_MIN_WIDTH:
952             if( rValue.indexOf( '%' ) != -1 )
953             {
954                 sal_Int32 nTmp;
955                 GetImport().GetMM100UnitConverter().convertPercent( nTmp,
956                                                                     rValue );
957                 nRelWidth = (sal_Int16)nTmp;
958             }
959             else
960             {
961                 GetImport().GetMM100UnitConverter().convertMeasure( nWidth,
962                                                                     rValue, 0 );
963             }
964             bMinWidth = sal_True;
965             break;
966         case XML_TOK_TEXT_FRAME_HEIGHT:
967             // relative heights are obsolete since SRC617. Remove them some day!
968             if( rValue.indexOf( '%' ) != -1 )
969             {
970                 sal_Int32 nTmp;
971                 GetImport().GetMM100UnitConverter().convertPercent( nTmp,
972                                                                     rValue );
973                 nRelHeight = (sal_Int16)nTmp;
974             }
975             else
976             {
977                 GetImport().GetMM100UnitConverter().convertMeasure( nHeight,
978                                                                     rValue, 0 );
979             }
980             break;
981         case XML_TOK_TEXT_FRAME_REL_HEIGHT:
982             if( IsXMLToken( rValue, XML_SCALE ) )
983             {
984                 bSyncHeight = sal_True;
985             }
986             else if( IsXMLToken( rValue, XML_SCALE_MIN ) )
987             {
988                 bSyncHeight = sal_True;
989                 bMinHeight = sal_True;
990             }
991             else
992             {
993                 sal_Int32 nTmp;
994                 if( GetImport().GetMM100UnitConverter().
995                         convertPercent( nTmp, rValue ) )
996                     nRelHeight = (sal_Int16)nTmp;
997             }
998             break;
999         case XML_TOK_TEXT_FRAME_MIN_HEIGHT:
1000             if( rValue.indexOf( '%' ) != -1 )
1001             {
1002                 sal_Int32 nTmp;
1003                 GetImport().GetMM100UnitConverter().convertPercent( nTmp,
1004                                                                     rValue );
1005                 nRelHeight = (sal_Int16)nTmp;
1006             }
1007             else
1008             {
1009                 GetImport().GetMM100UnitConverter().convertMeasure( nHeight,
1010                                                                     rValue, 0 );
1011             }
1012             bMinHeight = sal_True;
1013             break;
1014         case XML_TOK_TEXT_FRAME_Z_INDEX:
1015             GetImport().GetMM100UnitConverter().convertNumber( nZIndex, rValue, -1 );
1016             break;
1017         case XML_TOK_TEXT_FRAME_NEXT_CHAIN_NAME:
1018             sNextName = rValue;
1019             break;
1020         case XML_TOK_TEXT_FRAME_HREF:
1021             sHRef = rValue;
1022             break;
1023         case XML_TOK_TEXT_FRAME_FILTER_NAME:
1024             sFilterName = rValue;
1025             break;
1026         case XML_TOK_TEXT_FRAME_TRANSFORM:
1027             {
1028                 OUString sValue( rValue );
1029                 sValue.trim();
1030                 const OUString aRotate(GetXMLToken(XML_ROTATE));
1031                 const sal_Int32 nRotateLen(aRotate.getLength());
1032                 sal_Int32 nLen = sValue.getLength();
1033                 if( nLen >= nRotateLen+3 &&
1034                     0 == sValue.compareTo( aRotate, nRotateLen ) &&
1035                     '(' == sValue[nRotateLen] &&
1036                     ')' == sValue[nLen-1] )
1037                 {
1038                     sValue = sValue.copy( nRotateLen+1, nLen-(nRotateLen+2) );
1039                     sValue.trim();
1040                     sal_Int32 nVal;
1041                     if( GetImport().GetMM100UnitConverter().convertNumber( nVal, sValue ) )
1042                         nRotation = (sal_Int16)(nVal % 360 );
1043                 }
1044             }
1045             break;
1046         case XML_TOK_TEXT_FRAME_CODE:
1047             sCode = rValue;
1048             break;
1049         case XML_TOK_TEXT_FRAME_OBJECT:
1050             sObject = rValue;
1051             break;
1052         case XML_TOK_TEXT_FRAME_ARCHIVE:
1053             sArchive = rValue;
1054             break;
1055         case XML_TOK_TEXT_FRAME_MAY_SCRIPT:
1056             bMayScript = IsXMLToken( rValue, XML_TRUE );
1057             break;
1058         case XML_TOK_TEXT_FRAME_MIME_TYPE:
1059             sMimeType = rValue;
1060             break;
1061         case XML_TOK_TEXT_FRAME_NOTIFY_ON_UPDATE:
1062             sTblName = rValue;
1063             break;
1064         }
1065     }
1066 
1067     if( ( (XML_TEXT_FRAME_GRAPHIC == nType ||
1068            XML_TEXT_FRAME_OBJECT == nType ||
1069            XML_TEXT_FRAME_OBJECT_OLE == nType) &&
1070           !sHRef.getLength() ) ||
1071         ( XML_TEXT_FRAME_APPLET  == nType && !sCode.getLength() ) ||
1072         ( XML_TEXT_FRAME_PLUGIN == nType &&
1073           sHRef.getLength() == 0 && sMimeType.getLength() == 0 ) )
1074         return; // no URL: no image or OLE object
1075 
1076     Create( sal_True );
1077 }
1078 
1079 XMLTextFrameContext_Impl::~XMLTextFrameContext_Impl()
1080 {
1081 }
1082 
1083 void XMLTextFrameContext_Impl::EndElement()
1084 {
1085     CreateIfNotThere();
1086 
1087     if( xOldTextCursor.is() )
1088     {
1089         GetImport().GetTextImport()->DeleteParagraph();
1090         GetImport().GetTextImport()->SetCursor( xOldTextCursor );
1091     }
1092 
1093     // reinstall old list item (if necessary) #89892#
1094     if (mbListContextPushed) {
1095         GetImport().GetTextImport()->PopListContext();
1096     }
1097 
1098     if (( nType == XML_TEXT_FRAME_APPLET || nType == XML_TEXT_FRAME_PLUGIN ) && xPropSet.is())
1099         GetImport().GetTextImport()->endAppletOrPlugin( xPropSet, aParamMap);
1100 }
1101 
1102 SvXMLImportContext *XMLTextFrameContext_Impl::CreateChildContext(
1103         sal_uInt16 nPrefix,
1104         const OUString& rLocalName,
1105         const Reference< XAttributeList > & xAttrList )
1106 {
1107     SvXMLImportContext *pContext = 0;
1108 
1109     if( XML_NAMESPACE_DRAW == nPrefix )
1110     {
1111         if ( (nType == XML_TEXT_FRAME_APPLET || nType == XML_TEXT_FRAME_PLUGIN) &&
1112               IsXMLToken( rLocalName, XML_PARAM ) )
1113         {
1114             pContext = new XMLTextFrameParam_Impl( GetImport(),
1115                                               nPrefix, rLocalName,
1116                                               xAttrList, nType, aParamMap );
1117         }
1118     }
1119     else if( (XML_NAMESPACE_OFFICE == nPrefix) )
1120     {
1121         if( IsXMLToken( rLocalName, XML_BINARY_DATA ) )
1122         {
1123             if( !xPropSet.is() && !xBase64Stream.is() && !bCreateFailed )
1124             {
1125                 switch( nType )
1126                 {
1127                 case XML_TEXT_FRAME_GRAPHIC:
1128                     xBase64Stream =
1129                         GetImport().GetStreamForGraphicObjectURLFromBase64();
1130                     break;
1131                 case XML_TEXT_FRAME_OBJECT_OLE:
1132                     xBase64Stream =
1133                         GetImport().GetStreamForEmbeddedObjectURLFromBase64();
1134                     break;
1135                 }
1136                 if( xBase64Stream.is() )
1137                     pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
1138                                                     rLocalName, xAttrList,
1139                                                     xBase64Stream );
1140             }
1141         }
1142     }
1143     // --> OD 2009-08-17 #i100480#
1144     // correction of condition which also avoids warnings.
1145     if( !pContext &&
1146         ( XML_TEXT_FRAME_OBJECT == nType &&
1147           ( ( XML_NAMESPACE_OFFICE == nPrefix &&
1148               IsXMLToken( rLocalName, XML_DOCUMENT ) ) ||
1149             ( XML_NAMESPACE_MATH == nPrefix &&
1150               IsXMLToken( rLocalName, XML_MATH ) ) ) ) )
1151     // <--
1152     {
1153         if( !xPropSet.is() && !bCreateFailed )
1154         {
1155             XMLEmbeddedObjectImportContext *pEContext =
1156                 new XMLEmbeddedObjectImportContext( GetImport(), nPrefix,
1157                                                     rLocalName, xAttrList );
1158             sFilterService = pEContext->GetFilterServiceName();
1159             if( sFilterService.getLength() != 0 )
1160             {
1161                 Create( sal_False );
1162                 if( xPropSet.is() )
1163                 {
1164                     Reference < XEmbeddedObjectSupplier > xEOS( xPropSet,
1165                                                                 UNO_QUERY );
1166                     OSL_ENSURE( xEOS.is(),
1167                             "no embedded object supplier for own object" );
1168                     Reference<com::sun::star::lang::XComponent> aXComponent(xEOS->getEmbeddedObject());
1169                     pEContext->SetComponent( aXComponent );
1170                 }
1171             }
1172             pContext = pEContext;
1173         }
1174     }
1175     if( !pContext && xOldTextCursor.is() )  // text-box
1176         pContext = GetImport().GetTextImport()->CreateTextChildContext(
1177                             GetImport(), nPrefix, rLocalName, xAttrList,
1178                             XML_TEXT_TYPE_TEXTBOX );
1179 
1180     if( !pContext )
1181         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1182 
1183     return pContext;
1184 }
1185 
1186 void XMLTextFrameContext_Impl::Characters( const OUString& rChars )
1187 {
1188     if( ( XML_TEXT_FRAME_OBJECT_OLE == nType ||
1189           XML_TEXT_FRAME_GRAPHIC == nType) &&
1190         !xPropSet.is() && !bCreateFailed )
1191     {
1192         OUString sTrimmedChars( rChars. trim() );
1193         if( sTrimmedChars.getLength() )
1194         {
1195             if( !xBase64Stream.is() )
1196             {
1197                 if( XML_TEXT_FRAME_GRAPHIC == nType )
1198                 {
1199                     xBase64Stream =
1200                         GetImport().GetStreamForGraphicObjectURLFromBase64();
1201                 }
1202                 else
1203                 {
1204                     xBase64Stream =
1205                         GetImport().GetStreamForEmbeddedObjectURLFromBase64();
1206                 }
1207                 if( xBase64Stream.is() )
1208                     bOwnBase64Stream = sal_True;
1209             }
1210             if( bOwnBase64Stream && xBase64Stream.is() )
1211             {
1212                 OUString sChars;
1213                 if( sBase64CharsLeft )
1214                 {
1215                     sChars = sBase64CharsLeft;
1216                     sChars += sTrimmedChars;
1217                     sBase64CharsLeft = OUString();
1218                 }
1219                 else
1220                 {
1221                     sChars = sTrimmedChars;
1222                 }
1223                 Sequence< sal_Int8 > aBuffer( (sChars.getLength() / 4) * 3 );
1224                 sal_Int32 nCharsDecoded =
1225                     GetImport().GetMM100UnitConverter().
1226                         decodeBase64SomeChars( aBuffer, sChars );
1227                 xBase64Stream->writeBytes( aBuffer );
1228                 if( nCharsDecoded != sChars.getLength() )
1229                     sBase64CharsLeft = sChars.copy( nCharsDecoded );
1230             }
1231         }
1232     }
1233 }
1234 
1235 void XMLTextFrameContext_Impl::SetHyperlink( const OUString& rHRef,
1236                        const OUString& rName,
1237                        const OUString& rTargetFrameName,
1238                        sal_Bool bMap )
1239 {
1240     static ::rtl::OUString s_HyperLinkURL(
1241         RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL"));
1242     static ::rtl::OUString s_HyperLinkName(
1243         RTL_CONSTASCII_USTRINGPARAM("HyperLinkName"));
1244     static ::rtl::OUString s_HyperLinkTarget(
1245         RTL_CONSTASCII_USTRINGPARAM("HyperLinkTarget"));
1246     static ::rtl::OUString s_ServerMap(
1247         RTL_CONSTASCII_USTRINGPARAM("ServerMap"));
1248     if( !xPropSet.is() )
1249         return;
1250 
1251     UniReference< XMLTextImportHelper > xTxtImp = GetImport().GetTextImport();
1252     Reference < XPropertySetInfo > xPropSetInfo =
1253         xPropSet->getPropertySetInfo();
1254     if( !xPropSetInfo.is() ||
1255         !xPropSetInfo->hasPropertyByName(s_HyperLinkURL))
1256         return;
1257 
1258     Any aAny;
1259     aAny <<= rHRef;
1260     xPropSet->setPropertyValue( s_HyperLinkURL, aAny );
1261 
1262     if (xPropSetInfo->hasPropertyByName(s_HyperLinkName))
1263     {
1264         aAny <<= rName;
1265         xPropSet->setPropertyValue(s_HyperLinkName, aAny);
1266     }
1267 
1268     if (xPropSetInfo->hasPropertyByName(s_HyperLinkTarget))
1269     {
1270         aAny <<= rTargetFrameName;
1271         xPropSet->setPropertyValue( s_HyperLinkTarget, aAny );
1272     }
1273 
1274     if (xPropSetInfo->hasPropertyByName(s_ServerMap))
1275     {
1276         aAny.setValue( &bMap, ::getBooleanCppuType() );
1277         xPropSet->setPropertyValue(s_ServerMap, aAny);
1278     }
1279 }
1280 
1281 // --> OD 2009-07-22 #i73249#
1282 void XMLTextFrameContext_Impl::SetTitle( const OUString& rTitle )
1283 {
1284     if ( xPropSet.is() )
1285     {
1286         Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1287         if( xPropSetInfo->hasPropertyByName( sTitle ) )
1288         {
1289             xPropSet->setPropertyValue( sTitle, makeAny( rTitle ) );
1290         }
1291     }
1292 }
1293 
1294 void XMLTextFrameContext_Impl::SetDesc( const OUString& rDesc )
1295 {
1296     if ( xPropSet.is() )
1297     {
1298         Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1299         if( xPropSetInfo->hasPropertyByName( sDescription ) )
1300         {
1301             xPropSet->setPropertyValue( sDescription, makeAny( rDesc ) );
1302         }
1303     }
1304 }
1305 // <--
1306 
1307 //-----------------------------------------------------------------------------------------------------
1308 
1309 TYPEINIT1( XMLTextFrameContext, SvXMLImportContext );
1310 
1311 sal_Bool XMLTextFrameContext::CreateIfNotThere()
1312 {
1313     sal_Bool bRet = sal_False;
1314     SvXMLImportContext *pContext = &m_xImplContext;
1315     XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1316     if( pImpl )
1317         bRet = pImpl->CreateIfNotThere();
1318 
1319     return bRet;
1320 }
1321 
1322 sal_Bool XMLTextFrameContext::CreateIfNotThere( ::com::sun::star::uno::Reference <
1323         ::com::sun::star::beans::XPropertySet >& rPropSet )
1324 {
1325     SvXMLImportContext *pContext = &m_xImplContext;
1326     XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1327     if( pImpl )
1328     {
1329         if( pImpl->CreateIfNotThere() )
1330             rPropSet = pImpl->GetPropSet();
1331     }
1332 
1333     return rPropSet.is();
1334 }
1335 
1336 XMLTextFrameContext::XMLTextFrameContext(
1337         SvXMLImport& rImport,
1338         sal_uInt16 nPrfx, const OUString& rLName,
1339         const Reference< XAttributeList > & xAttrList,
1340         TextContentAnchorType eATyp )
1341 :   SvXMLImportContext( rImport, nPrfx, rLName )
1342 ,   m_xAttrList( new SvXMLAttributeList( xAttrList ) )
1343 ,   m_pHyperlink( 0 )
1344 // --> OD 2009-07-22 #i73249#
1345 ,   m_sTitle()
1346 ,   m_sDesc()
1347 // <--
1348 ,   m_eDefaultAnchorType( eATyp )
1349     // --> OD 2006-03-10 #i51726#
1350 ,   m_HasAutomaticStyleWithoutParentStyle( sal_False )
1351     // <--
1352 ,   m_bSupportsReplacement( sal_False )
1353 {
1354     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1355     for( sal_Int16 i=0; i < nAttrCount; i++ )
1356     {
1357         const OUString& rAttrName = xAttrList->getNameByIndex( i );
1358 
1359         OUString aLocalName;
1360         sal_uInt16 nPrefix =
1361             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
1362         // --> OD 2006-03-10 #i51726#
1363         // New distinguish attribute between Writer objects and Draw objects is:
1364         // Draw objects have an automatic style without a parent style
1365         if ( XML_NAMESPACE_DRAW == nPrefix &&
1366              IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1367         {
1368             OUString aStyleName = xAttrList->getValueByIndex( i );
1369             if( aStyleName.getLength() )
1370             {
1371                 UniReference < XMLTextImportHelper > xTxtImport =
1372                                                     GetImport().GetTextImport();
1373                 XMLPropStyleContext* pStyle( 0L );
1374                 pStyle = xTxtImport->FindAutoFrameStyle( aStyleName );
1375                 if ( pStyle && !pStyle->GetParentName().getLength() )
1376                 {
1377                     m_HasAutomaticStyleWithoutParentStyle = sal_True;
1378                 }
1379             }
1380         }
1381         // <--
1382         else if ( XML_NAMESPACE_TEXT == nPrefix &&
1383                   IsXMLToken( aLocalName, XML_ANCHOR_TYPE ) )
1384         {
1385             TextContentAnchorType eNew;
1386             if( XMLAnchorTypePropHdl::convert( xAttrList->getValueByIndex(i),
1387                         eNew ) &&
1388                 ( TextContentAnchorType_AT_PARAGRAPH == eNew ||
1389                   TextContentAnchorType_AT_CHARACTER == eNew ||
1390                   TextContentAnchorType_AS_CHARACTER == eNew ||
1391                   TextContentAnchorType_AT_PAGE == eNew) )
1392                 m_eDefaultAnchorType = eNew;
1393         }
1394     }
1395 }
1396 
1397 XMLTextFrameContext::~XMLTextFrameContext()
1398 {
1399     delete m_pHyperlink;
1400 }
1401 
1402 void XMLTextFrameContext::EndElement()
1403 {
1404     SvXMLImportContext *pContext = &m_xImplContext;
1405     XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1406     if( pImpl )
1407     {
1408         pImpl->CreateIfNotThere();
1409 
1410         // --> OD 2009-07-22 #i73249#
1411 //        // alternative text
1412 //        if( m_sDesc.getLength() )
1413 //            pImpl->SetDesc( m_sDesc );
1414         // svg:title
1415         if( m_sTitle.getLength() )
1416         {
1417             pImpl->SetTitle( m_sTitle );
1418         }
1419         if( m_sDesc.getLength() )
1420         {
1421             pImpl->SetDesc( m_sDesc );
1422         }
1423         // <--
1424 
1425         if( m_pHyperlink )
1426         {
1427             pImpl->SetHyperlink( m_pHyperlink->GetHRef(), m_pHyperlink->GetName(),
1428                           m_pHyperlink->GetTargetFrameName(), m_pHyperlink->GetMap() );
1429             delete m_pHyperlink;
1430             m_pHyperlink = 0;
1431         }
1432 
1433     }
1434 }
1435 
1436 SvXMLImportContext *XMLTextFrameContext::CreateChildContext(
1437         sal_uInt16 p_nPrefix,
1438         const OUString& rLocalName,
1439         const Reference< XAttributeList > & xAttrList )
1440 {
1441     SvXMLImportContext *pContext = 0;
1442 
1443     if( !m_xImplContext.Is() )
1444     {
1445         // no child exists
1446         if( XML_NAMESPACE_DRAW == p_nPrefix )
1447         {
1448             sal_uInt16 nFrameType = USHRT_MAX;
1449             if( IsXMLToken( rLocalName, XML_TEXT_BOX ) )
1450                 nFrameType = XML_TEXT_FRAME_TEXTBOX;
1451             else if( IsXMLToken( rLocalName, XML_IMAGE ) )
1452                 nFrameType = XML_TEXT_FRAME_GRAPHIC;
1453             else if( IsXMLToken( rLocalName, XML_OBJECT ) )
1454                 nFrameType = XML_TEXT_FRAME_OBJECT;
1455             else if( IsXMLToken( rLocalName, XML_OBJECT_OLE ) )
1456                 nFrameType = XML_TEXT_FRAME_OBJECT_OLE;
1457             else if( IsXMLToken( rLocalName, XML_APPLET) )
1458                 nFrameType = XML_TEXT_FRAME_APPLET;
1459             else if( IsXMLToken( rLocalName, XML_PLUGIN ) )
1460                 nFrameType = XML_TEXT_FRAME_PLUGIN;
1461             else if( IsXMLToken( rLocalName, XML_FLOATING_FRAME ) )
1462                 nFrameType = XML_TEXT_FRAME_FLOATING_FRAME;
1463 
1464             if( USHRT_MAX != nFrameType )
1465             {
1466                 // --> OD 2006-03-10 #i51726#
1467                 if ( ( XML_TEXT_FRAME_TEXTBOX == nFrameType ||
1468                        XML_TEXT_FRAME_GRAPHIC == nFrameType ) &&
1469                      m_HasAutomaticStyleWithoutParentStyle )
1470                 // <--
1471                 {
1472                     Reference < XShapes > xShapes;
1473                     pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
1474                                     GetImport(), p_nPrefix, rLocalName, xAttrList, xShapes, m_xAttrList );
1475                 }
1476                 else if( XML_TEXT_FRAME_PLUGIN == nFrameType )
1477                 {
1478                     bool bMedia = false;
1479 
1480                     // check, if we have a media object
1481                     for( sal_Int16 n = 0, nAttrCount = ( xAttrList.is() ? xAttrList->getLength() : 0 ); n < nAttrCount; ++n )
1482                     {
1483                         OUString    aLocalName;
1484                         sal_uInt16  nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( n ), &aLocalName );
1485 
1486                         if( nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( aLocalName, XML_MIME_TYPE ) )
1487                         {
1488                             if( 0 == xAttrList->getValueByIndex( n ).compareToAscii( "application/vnd.sun.star.media" ) )
1489                                 bMedia = true;
1490 
1491                             // leave this loop
1492                             n = nAttrCount - 1;
1493                         }
1494                     }
1495 
1496                     if( bMedia )
1497                     {
1498                         Reference < XShapes > xShapes;
1499                         pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
1500                                         GetImport(), p_nPrefix, rLocalName, xAttrList, xShapes, m_xAttrList );
1501                     }
1502                 }
1503                 else if( XML_TEXT_FRAME_OBJECT == nFrameType ||
1504                          XML_TEXT_FRAME_OBJECT_OLE == nFrameType )
1505                 {
1506                     m_bSupportsReplacement = sal_True;
1507                 }
1508 
1509                 if( !pContext )
1510                 {
1511 
1512                     pContext = new XMLTextFrameContext_Impl( GetImport(), p_nPrefix,
1513                                                         rLocalName, xAttrList,
1514                                                         m_eDefaultAnchorType,
1515                                                         nFrameType,
1516                                                         m_xAttrList );
1517                 }
1518 
1519                 m_xImplContext = pContext;
1520             }
1521         }
1522     }
1523     else if( m_bSupportsReplacement && !m_xReplImplContext &&
1524              XML_NAMESPACE_DRAW == p_nPrefix &&
1525              IsXMLToken( rLocalName, XML_IMAGE ) )
1526     {
1527         // read replacement image
1528         Reference < XPropertySet > xPropSet;
1529         if( CreateIfNotThere( xPropSet ) )
1530         {
1531             pContext = new XMLReplacementImageContext( GetImport(),
1532                                 p_nPrefix, rLocalName, xAttrList, xPropSet );
1533             m_xReplImplContext = pContext;
1534         }
1535     }
1536     else if( m_xImplContext->ISA( XMLTextFrameContext_Impl ) )
1537     {
1538         // the child is a writer frame
1539         if( XML_NAMESPACE_SVG == p_nPrefix )
1540         {
1541             // --> OD 2009-07-22 #i73249#
1542 //            bool bOld = SvXMLImport::OOo_2x >= GetImport().getGeneratorVersion();
1543 //            if( IsXMLToken( rLocalName, bOld ? XML_DESC : XML_TITLE ) )
1544 //                pContext = new XMLTextFrameDescContext_Impl( GetImport(), p_nPrefix, rLocalName,
1545 //                                                         xAttrList, m_sDesc );
1546             const bool bOld = SvXMLImport::OOo_2x >= GetImport().getGeneratorVersion();
1547             if ( bOld )
1548             {
1549                 if ( IsXMLToken( rLocalName, XML_DESC ) )
1550                 {
1551                     pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1552                                                                         p_nPrefix,
1553                                                                         rLocalName,
1554                                                                         m_sTitle );
1555                 }
1556             }
1557             else
1558             {
1559                 if( IsXMLToken( rLocalName, XML_TITLE ) )
1560                 {
1561                     pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1562                                                                         p_nPrefix,
1563                                                                         rLocalName,
1564                                                                         m_sTitle );
1565                 }
1566                 else if ( IsXMLToken( rLocalName, XML_DESC ) )
1567                 {
1568                     pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1569                                                                         p_nPrefix,
1570                                                                         rLocalName,
1571                                                                         m_sDesc );
1572                 }
1573             }
1574             // <--
1575         }
1576         else if( XML_NAMESPACE_DRAW == p_nPrefix )
1577         {
1578             Reference < XPropertySet > xPropSet;
1579             if( IsXMLToken( rLocalName, XML_CONTOUR_POLYGON ) )
1580             {
1581                 if( CreateIfNotThere( xPropSet ) )
1582                     pContext = new XMLTextFrameContourContext_Impl( GetImport(), p_nPrefix, rLocalName,
1583                                                   xAttrList, xPropSet, sal_False );
1584             }
1585             else if( IsXMLToken( rLocalName, XML_CONTOUR_PATH ) )
1586             {
1587                 if( CreateIfNotThere( xPropSet ) )
1588                     pContext = new XMLTextFrameContourContext_Impl( GetImport(), p_nPrefix, rLocalName,
1589                                                   xAttrList, xPropSet, sal_True );
1590             }
1591             else if( IsXMLToken( rLocalName, XML_IMAGE_MAP ) )
1592             {
1593                 if( CreateIfNotThere( xPropSet ) )
1594                     pContext = new XMLImageMapContext( GetImport(), p_nPrefix, rLocalName, xPropSet );
1595             }
1596         }
1597         else if( (XML_NAMESPACE_OFFICE == p_nPrefix) && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
1598         {
1599             // do we still have the frame object?
1600             Reference < XPropertySet > xPropSet;
1601             if( CreateIfNotThere( xPropSet ) )
1602             {
1603                 // is it an event supplier?
1604                 Reference<XEventsSupplier> xEventsSupplier(xPropSet, UNO_QUERY);
1605                 if (xEventsSupplier.is())
1606                 {
1607                     // OK, we have the events, so create the context
1608                     pContext = new XMLEventsImportContext(GetImport(), p_nPrefix,
1609                                                       rLocalName, xEventsSupplier);
1610                 }
1611             }
1612         }
1613     }
1614     else if( p_nPrefix == XML_NAMESPACE_SVG &&  // #i68101#
1615                 (IsXMLToken( rLocalName, XML_TITLE ) || IsXMLToken( rLocalName, XML_DESC ) ) )
1616     {
1617         pContext = m_xImplContext->CreateChildContext( p_nPrefix, rLocalName, xAttrList );
1618     }
1619     else
1620     {
1621         // the child is a drawing shape
1622         pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
1623                                     &m_xImplContext, p_nPrefix, rLocalName, xAttrList );
1624     }
1625 
1626     if( !pContext )
1627         pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
1628 
1629     return pContext;
1630 }
1631 
1632 void XMLTextFrameContext::SetHyperlink( const OUString& rHRef,
1633                        const OUString& rName,
1634                        const OUString& rTargetFrameName,
1635                        sal_Bool bMap )
1636 {
1637     OSL_ENSURE( !m_pHyperlink, "recursive SetHyperlink call" );
1638     delete m_pHyperlink;
1639     m_pHyperlink = new XMLTextFrameContextHyperlink_Impl(
1640                 rHRef, rName, rTargetFrameName, bMap );
1641 }
1642 
1643 TextContentAnchorType XMLTextFrameContext::GetAnchorType() const
1644 {
1645     SvXMLImportContext *pContext = &m_xImplContext;
1646     XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1647     if( pImpl )
1648         return pImpl->GetAnchorType();
1649     else
1650         return m_eDefaultAnchorType;
1651 }
1652 
1653 Reference < XTextContent > XMLTextFrameContext::GetTextContent() const
1654 {
1655     Reference < XTextContent > xTxtCntnt;
1656     SvXMLImportContext *pContext = &m_xImplContext;
1657     XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1658     if( pImpl )
1659         xTxtCntnt.set( pImpl->GetPropSet(), UNO_QUERY );
1660 
1661     return xTxtCntnt;
1662 }
1663 
1664 // --> OD 2004-08-24 #33242#
1665 Reference < XShape > XMLTextFrameContext::GetShape() const
1666 {
1667     Reference < XShape > xShape;
1668     SvXMLImportContext* pContext = &m_xImplContext;
1669     SvXMLShapeContext* pImpl = PTR_CAST( SvXMLShapeContext, pContext );
1670     if ( pImpl )
1671     {
1672         xShape = pImpl->getShape();
1673     }
1674 
1675     return xShape;
1676 }
1677 // <--
1678