xref: /trunk/main/xmloff/source/draw/shapeexport.cxx (revision 46c69c84579d1f1df536015e7d54c9965db90b69)
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 
27 #include <memory>
28 
29 #include "unointerfacetouniqueidentifiermapper.hxx"
30 #include <com/sun/star/presentation/ClickAction.hpp>
31 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
32 #include <com/sun/star/container/XChild.hpp>
33 #include <com/sun/star/text/XText.hpp>
34 #include <com/sun/star/chart/XChartDocument.hpp>
35 #include <com/sun/star/drawing/XControlShape.hpp>
36 #include <com/sun/star/style/XStyle.hpp>
37 #include <com/sun/star/drawing/XGluePointsSupplier.hpp>
38 #include <com/sun/star/container/XIdentifierAccess.hpp>
39 #include <com/sun/star/drawing/GluePoint2.hpp>
40 #include <com/sun/star/drawing/Alignment.hpp>
41 #include <com/sun/star/drawing/EscapeDirection.hpp>
42 #include <com/sun/star/table/XColumnRowRange.hpp>
43 #include <xmloff/xmluconv.hxx>
44 #include "PropertySetMerger.hxx"
45 
46 #include <xmloff/shapeexport.hxx>
47 #include "sdpropls.hxx"
48 #include "sdxmlexp_impl.hxx"
49 #include <xmloff/families.hxx>
50 #include <tools/debug.hxx>
51 #include <xmloff/contextid.hxx>
52 #include <xmloff/xmltoken.hxx>
53 #include <tools/string.hxx>
54 #include <sot/clsids.hxx>
55 #include <tools/globname.hxx>
56 #include <com/sun/star/beans/XPropertyState.hpp>
57 
58 #include <comphelper/processfactory.hxx>
59 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
60 #include <com/sun/star/drawing/XCustomShapeEngine.hpp>
61 
62 #include "xmloff/xmlnmspe.hxx"
63 #include <xmloff/nmspmap.hxx>
64 #include <xmloff/xmltypes.hxx>
65 #include <unotools/saveopt.hxx>
66 
67 using ::rtl::OUString;
68 using ::rtl::OUStringBuffer;
69 
70 using namespace ::com::sun::star;
71 using namespace ::xmloff::token;
72 
73 //////////////////////////////////////////////////////////////////////////////
74 
XMLShapeExport(SvXMLExport & rExp,SvXMLExportPropertyMapper * pExtMapper)75 XMLShapeExport::XMLShapeExport(SvXMLExport& rExp,
76                                 SvXMLExportPropertyMapper *pExtMapper )
77 :   mrExport( rExp ),
78     mnNextUniqueShapeId(1),
79     maShapesInfos(),
80     maCurrentShapesIter(maShapesInfos.end()),
81     mbExportLayer( sal_False ),
82     // #88546# init to sal_False
83     mbHandleProgressBar( sal_False ),
84     msZIndex( RTL_CONSTASCII_USTRINGPARAM("ZOrder") ),
85     msPrintable( RTL_CONSTASCII_USTRINGPARAM("Printable") ),
86     msVisible( RTL_CONSTASCII_USTRINGPARAM("Visible") ),
87     msEmptyPres( RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ),
88     msModel( RTL_CONSTASCII_USTRINGPARAM("Model") ),
89     msStartShape( RTL_CONSTASCII_USTRINGPARAM("StartShape") ),
90     msEndShape( RTL_CONSTASCII_USTRINGPARAM("EndShape") ),
91     msOnClick( RTL_CONSTASCII_USTRINGPARAM("OnClick") ),
92 #ifdef ISSUE66550_HLINK_FOR_SHAPES
93     msOnAction( RTL_CONSTASCII_USTRINGPARAM("OnAction") ),
94     msAction( RTL_CONSTASCII_USTRINGPARAM("Action") ),
95     msURL( RTL_CONSTASCII_USTRINGPARAM("URL") ),
96 #endif
97     msEventType( RTL_CONSTASCII_USTRINGPARAM("EventType") ),
98     msPresentation( RTL_CONSTASCII_USTRINGPARAM("Presentation") ),
99     msMacroName( RTL_CONSTASCII_USTRINGPARAM("MacroName") ),
100     msScript( RTL_CONSTASCII_USTRINGPARAM("Script") ),
101     msLibrary( RTL_CONSTASCII_USTRINGPARAM("Library") ),
102     msClickAction( RTL_CONSTASCII_USTRINGPARAM("ClickAction") ),
103     msBookmark( RTL_CONSTASCII_USTRINGPARAM("Bookmark") ),
104     msEffect( RTL_CONSTASCII_USTRINGPARAM("Effect") ),
105     msPlayFull( RTL_CONSTASCII_USTRINGPARAM("PlayFull") ),
106     msVerb( RTL_CONSTASCII_USTRINGPARAM("Verb") ),
107     msSoundURL( RTL_CONSTASCII_USTRINGPARAM("SoundURL") ),
108     msSpeed( RTL_CONSTASCII_USTRINGPARAM("Speed") ),
109     msStarBasic( RTL_CONSTASCII_USTRINGPARAM("StarBasic") )
110 {
111     // construct PropertyHandlerFactory
112     mxSdPropHdlFactory = new XMLSdPropHdlFactory( mrExport.GetModel(), rExp );
113     // construct PropertySetMapper
114     mxPropertySetMapper = CreateShapePropMapper( mrExport );
115     if( pExtMapper )
116     {
117         UniReference < SvXMLExportPropertyMapper > xExtMapper( pExtMapper );
118         mxPropertySetMapper->ChainExportMapper( xExtMapper );
119     }
120 
121 /*
122     // chain text attributes
123     xPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaExtPropMapper(rExp));
124 */
125 
126     mrExport.GetAutoStylePool()->AddFamily(
127         XML_STYLE_FAMILY_SD_GRAPHICS_ID,
128         OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME)),
129         GetPropertySetMapper(),
130         OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_PREFIX)));
131     mrExport.GetAutoStylePool()->AddFamily(
132         XML_STYLE_FAMILY_SD_PRESENTATION_ID,
133         OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_PRESENTATION_NAME)),
134         GetPropertySetMapper(),
135         OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_PRESENTATION_PREFIX)));
136 
137     maCurrentInfo = maShapeInfos.end();
138 
139     // create table export helper and let him add his families in time
140     GetShapeTableExport();
141 }
142 
143 ///////////////////////////////////////////////////////////////////////
144 
~XMLShapeExport()145 XMLShapeExport::~XMLShapeExport()
146 {
147 }
148 
149 ///////////////////////////////////////////////////////////////////////
150 
151 // sj: replacing CustomShapes with standard objects that are also supported in OpenOffice.org format
checkForCustomShapeReplacement(const uno::Reference<drawing::XShape> & xShape)152 uno::Reference< drawing::XShape > XMLShapeExport::checkForCustomShapeReplacement( const uno::Reference< drawing::XShape >& xShape )
153 {
154     uno::Reference< drawing::XShape > xCustomShapeReplacement;
155 
156     if( ( GetExport().getExportFlags() & EXPORT_OASIS ) == 0 )
157     {
158         String aType( (OUString)xShape->getShapeType() );
159         if( aType.EqualsAscii( (const sal_Char*)"com.sun.star.drawing.CustomShape" ) )
160         {
161             uno::Reference< beans::XPropertySet > xSet( xShape, uno::UNO_QUERY );
162             if( xSet.is() )
163             {
164                 rtl::OUString aEngine;
165                 xSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "CustomShapeEngine" ) ) ) >>= aEngine;
166                 if ( !aEngine.getLength() )
167                     aEngine = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.EnhancedCustomShapeEngine" ) );
168 
169                 uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
170         /*
171                 uno::Reference< drawing::XShape > aXShape = GetXShapeForSdrObject( (SdrObjCustomShape*)pCustomShape );
172                 if ( !aXShape.is() )
173                     aXShape = new SvxCustomShape( (SdrObjCustomShape*)pCustomShape );
174         */
175                 if ( aEngine.getLength() && xFactory.is() )
176                 {
177                     uno::Sequence< uno::Any > aArgument( 1 );
178                     uno::Sequence< beans::PropertyValue > aPropValues( 2 );
179                     aPropValues[ 0 ].Name = rtl::OUString::createFromAscii( "CustomShape" );
180                     aPropValues[ 0 ].Value <<= xShape;
181                     sal_Bool bForceGroupWithText = sal_True;
182                     aPropValues[ 1 ].Name = rtl::OUString::createFromAscii( "ForceGroupWithText" );
183                     aPropValues[ 1 ].Value <<= bForceGroupWithText;
184                     aArgument[ 0 ] <<= aPropValues;
185                     uno::Reference< uno::XInterface > xInterface( xFactory->createInstanceWithArguments( aEngine, aArgument ) );
186                     if ( xInterface.is() )
187                     {
188                         uno::Reference< drawing::XCustomShapeEngine > xCustomShapeEngine(
189                             uno::Reference< drawing::XCustomShapeEngine >( xInterface, uno::UNO_QUERY ) );
190                         if ( xCustomShapeEngine.is() )
191                             xCustomShapeReplacement = xCustomShapeEngine->render();
192                     }
193                 }
194             }
195         }
196     }
197     return xCustomShapeReplacement;
198 }
199 
200 // This method collects all automatic styles for the given XShape
collectShapeAutoStyles(const uno::Reference<drawing::XShape> & xShape)201 void XMLShapeExport::collectShapeAutoStyles(const uno::Reference< drawing::XShape >& xShape )
202 {
203     if( maCurrentShapesIter == maShapesInfos.end() )
204     {
205         DBG_ERROR( "XMLShapeExport::collectShapeAutoStyles(): no call to seekShapes()!" );
206         return;
207     }
208     sal_Int32 nZIndex = 0;
209     uno::Reference< beans::XPropertySet > xSet( xShape, uno::UNO_QUERY );
210     if( xSet.is() )
211         xSet->getPropertyValue(msZIndex) >>= nZIndex;
212 
213     ImplXMLShapeExportInfoVector& aShapeInfoVector = (*maCurrentShapesIter).second;
214 
215     if( (sal_Int32)aShapeInfoVector.size() <= nZIndex )
216     {
217         DBG_ERROR( "XMLShapeExport::collectShapeAutoStyles(): no shape info allocated for a given shape" );
218         return;
219     }
220 
221     ImplXMLShapeExportInfo& aShapeInfo = aShapeInfoVector[nZIndex];
222 
223     uno::Reference< drawing::XShape > xCustomShapeReplacement = checkForCustomShapeReplacement( xShape );
224     if ( xCustomShapeReplacement.is() )
225         aShapeInfo.xCustomShapeReplacement = xCustomShapeReplacement;
226 
227     // -----------------------------
228     // first compute the shapes type
229     // -----------------------------
230     ImpCalcShapeType(xShape, aShapeInfo.meShapeType);
231 
232     // #i118485# enabled XmlShapeTypeDrawChartShape and XmlShapeTypeDrawOLE2Shape
233     // to have text
234     const bool bObjSupportsText =
235 //      aShapeInfo.meShapeType != XmlShapeTypeDrawControlShape &&
236         aShapeInfo.meShapeType != XmlShapeTypePresChartShape &&
237         aShapeInfo.meShapeType != XmlShapeTypePresOLE2Shape &&
238         aShapeInfo.meShapeType != XmlShapeTypeDrawSheetShape &&
239         aShapeInfo.meShapeType != XmlShapeTypePresSheetShape &&
240         aShapeInfo.meShapeType != XmlShapeTypeDraw3DSceneObject &&
241         aShapeInfo.meShapeType != XmlShapeTypeDraw3DCubeObject &&
242         aShapeInfo.meShapeType != XmlShapeTypeDraw3DSphereObject &&
243         aShapeInfo.meShapeType != XmlShapeTypeDraw3DLatheObject &&
244         aShapeInfo.meShapeType != XmlShapeTypeDraw3DExtrudeObject &&
245         aShapeInfo.meShapeType != XmlShapeTypeDrawPageShape &&
246         aShapeInfo.meShapeType != XmlShapeTypePresPageShape &&
247         aShapeInfo.meShapeType != XmlShapeTypeDrawGroupShape;
248 
249     const bool bObjSupportsStyle =
250         aShapeInfo.meShapeType != XmlShapeTypeDrawGroupShape;
251 
252     sal_Bool bIsEmptyPresObj = sal_False;
253 
254     uno::Reference< beans::XPropertySet > xPropSet(xShape, uno::UNO_QUERY);
255     if ( aShapeInfo.xCustomShapeReplacement.is() )
256         xPropSet.clear();
257 
258     // ----------------
259     // prep text styles
260     // ----------------
261     if( xPropSet.is() && bObjSupportsText )
262     {
263         uno::Reference< text::XText > xText(xShape, uno::UNO_QUERY);
264         if(xText.is() && xText->getString().getLength())
265         {
266             uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xPropSet->getPropertySetInfo() );
267 
268             if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(msEmptyPres) )
269             {
270                 uno::Any aAny = xPropSet->getPropertyValue(msEmptyPres);
271                 aAny >>= bIsEmptyPresObj;
272             }
273 
274             if(!bIsEmptyPresObj)
275             {
276                 GetExport().GetTextParagraphExport()->collectTextAutoStyles( xText );
277             }
278         }
279     }
280 
281     // ------------------------------
282     // compute the shape parent style
283     // ------------------------------
284     if( xPropSet.is() )
285     {
286         uno::Reference< beans::XPropertySetInfo > xPropertySetInfo( xPropSet->getPropertySetInfo() );
287 
288         OUString aParentName;
289         uno::Reference< style::XStyle > xStyle;
290 
291         if( bObjSupportsStyle )
292         {
293             if( xPropertySetInfo.is() && xPropertySetInfo->hasPropertyByName( OUString(RTL_CONSTASCII_USTRINGPARAM("Style"))) )
294                 xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Style"))) >>= xStyle;
295 
296             if(xStyle.is())
297             {
298                 // get family ID
299                 uno::Reference< beans::XPropertySet > xStylePropSet(xStyle, uno::UNO_QUERY);
300                 DBG_ASSERT( xStylePropSet.is(), "style without a XPropertySet?" );
301                 try
302                 {
303                     if(xStylePropSet.is())
304                     {
305                         OUString aFamilyName;
306                         xStylePropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Family"))) >>= aFamilyName;
307                         if(aFamilyName.getLength() && !aFamilyName.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("graphics"))))
308                             aShapeInfo.mnFamily = XML_STYLE_FAMILY_SD_PRESENTATION_ID;
309                     }
310                 }
311                 catch(beans::UnknownPropertyException aException)
312                 {
313                     // Ignored.
314                     DBG_ASSERT(false,
315                         "XMLShapeExport::collectShapeAutoStyles: style has no 'Family' property");
316                 }
317 
318                 // get parent-style name
319                 if(XML_STYLE_FAMILY_SD_PRESENTATION_ID == aShapeInfo.mnFamily)
320                 {
321                     aParentName = msPresentationStylePrefix;
322                 }
323 
324                 aParentName += xStyle->getName();
325             }
326         }
327 
328         // filter propset
329         std::vector< XMLPropertyState > xPropStates;
330 
331         sal_Int32 nCount = 0;
332         if( (!bIsEmptyPresObj || (aShapeInfo.meShapeType != XmlShapeTypePresPageShape)) )
333         {
334             xPropStates = GetPropertySetMapper()->Filter( xPropSet );
335 
336             if (XmlShapeTypeDrawControlShape == aShapeInfo.meShapeType)
337             {
338                 // for control shapes, we additionally need the number format style (if any)
339                 uno::Reference< drawing::XControlShape > xControl(xShape, uno::UNO_QUERY);
340                 DBG_ASSERT(xControl.is(), "XMLShapeExport::collectShapeAutoStyles: ShapeType control, but no XControlShape!");
341                 if (xControl.is())
342                 {
343                     uno::Reference< beans::XPropertySet > xControlModel(xControl->getControl(), uno::UNO_QUERY);
344                     DBG_ASSERT(xControlModel.is(), "XMLShapeExport::collectShapeAutoStyles: no control model on the control shape!");
345 
346                     ::rtl::OUString sNumberStyle = mrExport.GetFormExport()->getControlNumberStyle(xControlModel);
347                     if (0 != sNumberStyle.getLength())
348                     {
349                         sal_Int32 nIndex = GetPropertySetMapper()->getPropertySetMapper()->FindEntryIndex(CTF_SD_CONTROL_SHAPE_DATA_STYLE);
350                             // TODO : this retrieval of the index could be moved into the ctor, holding the index
351                             //          as member, thus saving time.
352                         DBG_ASSERT(-1 != nIndex, "XMLShapeExport::collectShapeAutoStyles: could not obtain the index for our context id!");
353 
354                         XMLPropertyState aNewState(nIndex, uno::makeAny(sNumberStyle));
355                         xPropStates.push_back(aNewState);
356                     }
357                 }
358             }
359 
360             std::vector< XMLPropertyState >::iterator aIter = xPropStates.begin();
361             std::vector< XMLPropertyState >::iterator aEnd = xPropStates.end();
362             while( aIter != aEnd )
363             {
364                 if( aIter->mnIndex != -1 )
365                     nCount++;
366                 aIter++;
367             }
368         }
369 
370         if(nCount == 0)
371         {
372             // no hard attributes, use parent style name for export
373             aShapeInfo.msStyleName = aParentName;
374         }
375         else
376         {
377             // there are filtered properties -> hard attributes
378             // try to find this style in AutoStylePool
379             aShapeInfo.msStyleName = mrExport.GetAutoStylePool()->Find(aShapeInfo.mnFamily, aParentName, xPropStates);
380 
381             if(!aShapeInfo.msStyleName.getLength())
382             {
383                 // Style did not exist, add it to AutoStalePool
384                 aShapeInfo.msStyleName = mrExport.GetAutoStylePool()->Add(aShapeInfo.mnFamily, aParentName, xPropStates);
385             }
386         }
387 
388         // optionaly generate auto style for text attributes
389         if( (!bIsEmptyPresObj || (aShapeInfo.meShapeType != XmlShapeTypePresPageShape)) && bObjSupportsText )
390         {
391             xPropStates = GetExport().GetTextParagraphExport()->GetParagraphPropertyMapper()->Filter( xPropSet );
392 
393             // ODF 1.4 Extended: the fill of the shape is in its own style, a paragraph style may not hold style:graphic-properties
394             if( SvtSaveOptions().GetODFDefaultVersion() == SvtSaveOptions::ODFVER_014_EXT )
395             {
396                 UniReference< XMLPropertySetMapper > xMapper( GetExport().GetTextParagraphExport()->GetParagraphPropertyMapper()->getPropertySetMapper() );
397                 for( ::std::vector< XMLPropertyState >::iterator aIter = xPropStates.begin(); aIter != xPropStates.end(); ++aIter )
398                 {
399                     if( aIter->mnIndex != -1 && ( xMapper->GetEntryType( aIter->mnIndex ) & XML_TYPE_PROP_MASK ) == XML_TYPE_PROP_GRAPHIC &&
400                         xMapper->GetEarliestODFVersionForExport( aIter->mnIndex ) == SvtSaveOptions::ODFVER_EXTENSION )
401                         aIter->mnIndex = -1;
402                 }
403             }
404 
405             // ----------------------------------------------------------------------
406             // yet more additionally, we need to care for the ParaAdjust property
407             if ( XmlShapeTypeDrawControlShape == aShapeInfo.meShapeType )
408             {
409                 uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xPropSet->getPropertySetInfo() );
410                 uno::Reference< beans::XPropertyState > xPropState( xPropSet, uno::UNO_QUERY );
411                 if ( xPropSetInfo.is() && xPropState.is() )
412                 {
413                     // this is because:
414                     // * if controls shapes have a ParaAdjust property, then this is the Align property of the control model
415                     // * control models are allowed to have an Align of "void"
416                     // * the Default for control model's Align is TextAlign_LEFT
417                     // * defaults for style properties are not written, but we need to write the "left",
418                     //   because we need to distinguish this "left" from the case where not align attribute
419                     //   is present which means "void"
420                     // 102407 - 2002-11-01 - fs@openoffice.org
421                     static const ::rtl::OUString s_sParaAdjustPropertyName( RTL_CONSTASCII_USTRINGPARAM( "ParaAdjust" ) );
422                     if  (   xPropSetInfo->hasPropertyByName( s_sParaAdjustPropertyName )
423                         &&  ( beans::PropertyState_DEFAULT_VALUE == xPropState->getPropertyState( s_sParaAdjustPropertyName ) )
424                         )
425                     {
426                         sal_Int32 nIndex = GetExport().GetTextParagraphExport()->GetParagraphPropertyMapper()->getPropertySetMapper()->FindEntryIndex( CTF_SD_SHAPE_PARA_ADJUST );
427                             // TODO : this retrieval of the index should be moved into the ctor, holding the index
428                             //          as member, thus saving time.
429                         DBG_ASSERT(-1 != nIndex, "XMLShapeExport::collectShapeAutoStyles: could not obtain the index for the ParaAdjust context id!");
430 
431                         uno::Any aParaAdjustValue = xPropSet->getPropertyValue( s_sParaAdjustPropertyName );
432                         XMLPropertyState aAlignDefaultState( nIndex, aParaAdjustValue );
433 
434                         xPropStates.push_back( aAlignDefaultState );
435                     }
436                 }
437             }
438             // ----------------------------------------------------------------------
439 
440             nCount = 0;
441             std::vector< XMLPropertyState >::iterator aIter = xPropStates.begin();
442             std::vector< XMLPropertyState >::iterator aEnd = xPropStates.end();
443             while( aIter != aEnd )
444             {
445                 if( aIter->mnIndex != -1 )
446                     nCount++;
447                 aIter++;
448             }
449 
450             if( nCount )
451             {
452                 const OUString aEmpty;
453                 aShapeInfo.msTextStyleName = mrExport.GetAutoStylePool()->Find( XML_STYLE_FAMILY_TEXT_PARAGRAPH, aEmpty, xPropStates );
454                 if(!aShapeInfo.msTextStyleName.getLength())
455                 {
456                     // Style did not exist, add it to AutoStalePool
457                     aShapeInfo.msTextStyleName = mrExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_TEXT_PARAGRAPH, aEmpty, xPropStates);
458                 }
459             }
460         }
461     }
462 
463     // ----------------------------------------
464     // prepare animation informations if needed
465     // ----------------------------------------
466     if( mxAnimationsExporter.is() )
467         mxAnimationsExporter->prepare( xShape, mrExport );
468 
469     // check for special shapes
470 
471     switch( aShapeInfo.meShapeType )
472     {
473         case XmlShapeTypeDrawConnectorShape:
474         {
475             uno::Reference< uno::XInterface > xConnection;
476 
477             // create shape ids for export later
478             xPropSet->getPropertyValue( msStartShape ) >>= xConnection;
479             if( xConnection.is() )
480                 mrExport.getInterfaceToIdentifierMapper().registerReference( xConnection );
481 
482             xPropSet->getPropertyValue( msEndShape ) >>= xConnection;
483             if( xConnection.is() )
484                 mrExport.getInterfaceToIdentifierMapper().registerReference( xConnection );
485             break;
486         }
487         case XmlShapeTypePresTableShape:
488         case XmlShapeTypeDrawTableShape:
489         {
490             try
491             {
492                 uno::Reference< table::XColumnRowRange > xRange( xSet->getPropertyValue( msModel ), uno::UNO_QUERY_THROW );
493                 GetShapeTableExport()->collectTableAutoStyles( xRange );
494             }
495             catch( uno::Exception& )
496             {
497                 DBG_ERROR( "XMLShapeExport::collectShapeAutoStyles(): exception caught while collection auto styles for a table!" );
498             }
499             break;
500         }
501         default:
502             break;
503     }
504 
505     maShapeInfos.push_back( aShapeInfo );
506     maCurrentInfo = maShapeInfos.begin();
507 
508     // -----------------------------------------------------
509     // check for shape collections (group shape or 3d scene)
510     // and collect contained shapes style infos
511     // -----------------------------------------------------
512     const uno::Reference< drawing::XShape >& xCollection = aShapeInfo.xCustomShapeReplacement.is()
513                                                 ? aShapeInfo.xCustomShapeReplacement : xShape;
514     {
515         uno::Reference< drawing::XShapes > xShapes( xCollection, uno::UNO_QUERY );
516         if( xShapes.is() )
517         {
518             collectShapesAutoStyles( xShapes );
519         }
520     }
521 }
522 
523 ///////////////////////////////////////////////////////////////////////
524 
525 // --> OD 2008-05-08 #refactorlists#
526 namespace
527 {
528     class NewTextListsHelper
529     {
530         public:
NewTextListsHelper(SvXMLExport & rExp)531             NewTextListsHelper( SvXMLExport& rExp )
532                 : mrExport( rExp )
533             {
534                 mrExport.GetTextParagraphExport()->PushNewTextListsHelper();
535             }
536 
~NewTextListsHelper()537             ~NewTextListsHelper()
538             {
539                 mrExport.GetTextParagraphExport()->PopTextListsHelper();
540             }
541 
542         private:
543             SvXMLExport& mrExport;
544     };
545 }
546 // This method exports the given XShape
exportShape(const uno::Reference<drawing::XShape> & xShape,sal_Int32 nFeatures,com::sun::star::awt::Point * pRefPoint,SvXMLAttributeList * pAttrList)547 void XMLShapeExport::exportShape(const uno::Reference< drawing::XShape >& xShape,
548                                  sal_Int32 nFeatures /* = SEF_DEFAULT */,
549                                  com::sun::star::awt::Point* pRefPoint /* = NULL */,
550                                  SvXMLAttributeList* pAttrList /* = NULL */ )
551 {
552     if( maCurrentShapesIter == maShapesInfos.end() )
553     {
554         DBG_ERROR( "XMLShapeExport::exportShape(): no auto styles where collected before export" );
555         return;
556     }
557     sal_Int32 nZIndex = 0;
558     uno::Reference< beans::XPropertySet > xSet( xShape, uno::UNO_QUERY );
559 
560 
561     ::std::unique_ptr< SvXMLElementExport >  mpHyperlinkElement;
562 
563     // export hyperlinks with <a><shape/></a>. Currently only in draw since draw
564     // does not support document events
565     if( xSet.is() && (GetExport().GetModelType() == SvtModuleOptions::E_DRAW) ) try
566     {
567         presentation::ClickAction eAction = presentation::ClickAction_NONE;
568         xSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("OnClick"))) >>= eAction;
569 
570         if( (eAction == presentation::ClickAction_DOCUMENT) ||
571             (eAction == presentation::ClickAction_BOOKMARK) )
572         {
573             OUString sURL;
574             xSet->getPropertyValue(msBookmark) >>= sURL;
575 
576             if( sURL.getLength() )
577             {
578                 mrExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sURL );
579                 mrExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
580                 mpHyperlinkElement.reset( new SvXMLElementExport(mrExport, XML_NAMESPACE_DRAW, XML_A, sal_True, sal_True) );
581             }
582         }
583     }
584     catch( uno::Exception& )
585     {
586         DBG_ERROR("XMLShapeExport::exportShape(): exception during hyperlink export");
587     }
588 
589 
590     if( xSet.is() )
591         xSet->getPropertyValue(msZIndex) >>= nZIndex;
592 
593     ImplXMLShapeExportInfoVector& aShapeInfoVector = (*maCurrentShapesIter).second;
594 
595     if( (sal_Int32)aShapeInfoVector.size() <= nZIndex )
596     {
597         DBG_ERROR( "XMLShapeExport::exportShape(): no shape info collected for a given shape" );
598         return;
599     }
600 
601     // --> OD 2008-05-08 #refactorlists#
602     NewTextListsHelper aNewTextListsHelper( mrExport );
603     // <--
604 
605     const ImplXMLShapeExportInfo& aShapeInfo = aShapeInfoVector[nZIndex];
606 
607 
608 #ifdef DBG_UTIL
609     // ---------------------------------------
610     // check if this is the correct ShapesInfo
611     // ---------------------------------------
612     uno::Reference< container::XChild > xChild( xShape, uno::UNO_QUERY );
613     if( xChild.is() )
614     {
615         uno::Reference< drawing::XShapes > xParent( xChild->getParent(), uno::UNO_QUERY );
616         DBG_ASSERT( xParent.is() && xParent.get() == (*maCurrentShapesIter).first.get(), "XMLShapeExport::exportShape(): Wrong call to XMLShapeExport::seekShapes()" );
617     }
618 
619     // -----------------------------
620     // first compute the shapes type
621     // -----------------------------
622     {
623         XmlShapeType eShapeType(XmlShapeTypeNotYetSet);
624         ImpCalcShapeType(xShape, eShapeType);
625 
626         DBG_ASSERT( eShapeType == aShapeInfo.meShapeType, "exportShape callings do not correspond to collectShapeAutoStyles calls!" );
627     }
628 #endif
629 
630     // ----------------------------------------
631     // collect animation informations if needed
632     // ----------------------------------------
633     if( mxAnimationsExporter.is() )
634         mxAnimationsExporter->collect( xShape, mrExport );
635 
636     // -------------------------------
637     // export shapes name if he has one
638     // --> OD 2006-03-13 #i51726#
639     // Export of the shape name for text documents only if the OpenDocument
640     // file format is written - exceptions are group shapes.
641     // Note: Writer documents in OpenOffice.org file format doesn't contain
642     //       any names for shapes, except for group shapes.
643     // -------------------------------
644     {
645         // --> OD 2006-03-10 #i51726#
646         if ( ( GetExport().GetModelType() != SvtModuleOptions::E_WRITER &&
647                GetExport().GetModelType() != SvtModuleOptions::E_WRITERWEB &&
648                GetExport().GetModelType() != SvtModuleOptions::E_WRITERGLOBAL ) ||
649              ( GetExport().getExportFlags() & EXPORT_OASIS ) != 0 ||
650              aShapeInfo.meShapeType == XmlShapeTypeDrawGroupShape ||
651              ( aShapeInfo.meShapeType == XmlShapeTypeDrawCustomShape &&
652                aShapeInfo.xCustomShapeReplacement.is() ) )
653         {
654             uno::Reference< container::XNamed > xNamed( xShape, uno::UNO_QUERY );
655             if( xNamed.is() )
656             {
657                 const OUString aName( xNamed->getName() );
658                 if( aName.getLength() )
659                     mrExport.AddAttribute(XML_NAMESPACE_DRAW, XML_NAME, aName );
660             }
661         }
662         // <--
663     }
664 
665     // ------------------
666     // export style name
667     // ------------------
668     if( aShapeInfo.msStyleName.getLength() != 0 )
669     {
670         if(XML_STYLE_FAMILY_SD_GRAPHICS_ID == aShapeInfo.mnFamily)
671             mrExport.AddAttribute(XML_NAMESPACE_DRAW, XML_STYLE_NAME, mrExport.EncodeStyleName( aShapeInfo.msStyleName) );
672         else
673             mrExport.AddAttribute(XML_NAMESPACE_PRESENTATION, XML_STYLE_NAME, mrExport.EncodeStyleName( aShapeInfo.msStyleName) );
674     }
675 
676     // ------------------
677     // export text style name
678     // ------------------
679     if( aShapeInfo.msTextStyleName.getLength() != 0 )
680     {
681         mrExport.AddAttribute(XML_NAMESPACE_DRAW, XML_TEXT_STYLE_NAME, aShapeInfo.msTextStyleName );
682     }
683 
684     // --------------------------
685     // export shapes id if needed
686     // --------------------------
687     {
688         uno::Reference< uno::XInterface > xRef( xShape, uno::UNO_QUERY );
689         const OUString& rShapeId = mrExport.getInterfaceToIdentifierMapper().getIdentifier( xRef );
690         if( rShapeId.getLength() )
691         {
692             mrExport.AddAttributeIdLegacy(XML_NAMESPACE_DRAW, rShapeId);
693         }
694     }
695 
696     // --------------------------
697     // export layer information
698     // --------------------------
699     if( IsLayerExportEnabled() )
700     {
701         // check for group or scene shape and not export layer if this is one
702         uno::Reference< drawing::XShapes > xShapes( xShape, uno::UNO_QUERY );
703         if( !xShapes.is() )
704         {
705             try
706             {
707                 uno::Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
708                 OUString aLayerName;
709                 xProps->getPropertyValue( OUString::createFromAscii( "LayerName" ) ) >>= aLayerName;
710                 mrExport.AddAttribute(XML_NAMESPACE_DRAW, XML_LAYER, aLayerName );
711 
712             }
713             catch( uno::Exception e )
714             {
715                 DBG_ERROR( "could not export layer name for shape!" );
716             }
717         }
718     }
719 
720     // export draw:display (do not export in ODF 1.2 or older)
721     if( xSet.is() && ( SvtSaveOptions::IsODFExtended( mrExport.getDefaultVersion() ) ) &&
722         mrExport.GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_DRAW_EXT ).getLength() )
723     {
724         if( aShapeInfo.meShapeType != XmlShapeTypeDrawPageShape && aShapeInfo.meShapeType != XmlShapeTypePresPageShape &&
725             aShapeInfo.meShapeType != XmlShapeTypeHandoutShape && aShapeInfo.meShapeType != XmlShapeTypeDrawChartShape )
726 
727         try
728         {
729             sal_Bool bVisible = sal_True;
730             sal_Bool bPrintable = sal_True;
731 
732             xSet->getPropertyValue(msVisible) >>= bVisible;
733             xSet->getPropertyValue(msPrintable) >>= bPrintable;
734 
735             XMLTokenEnum eDisplayToken = XML_TOKEN_INVALID;
736             const unsigned short nDisplay = (bVisible ? 2 : 0) | (bPrintable ? 1 : 0);
737             switch( nDisplay )
738             {
739             case 0: eDisplayToken = XML_NONE; break;
740             case 1: eDisplayToken = XML_PRINTER; break;
741             case 2: eDisplayToken = XML_SCREEN; break;
742             // case 3: eDisplayToken = XML_ALWAYS break; this is the default
743             }
744 
745             if( eDisplayToken != XML_TOKEN_INVALID )
746                 mrExport.AddAttribute(XML_NAMESPACE_DRAW_EXT, XML_DISPLAY, eDisplayToken );
747         }
748         catch( uno::Exception& )
749         {
750             DBG_ERROR( "XMLShapeExport::exportShape(), exception caught!" );
751         }
752     }
753 
754     // #82003# test export count
755     // #91587# ALWAYS increment since now ALL to be exported shapes are counted.
756     if(mrExport.GetShapeExport()->IsHandleProgressBarEnabled())
757     {
758         mrExport.GetProgressBarHelper()->Increment();
759     }
760 
761     onExport( xShape );
762 
763     // --------------------
764     // export shape element
765     // --------------------
766     switch(aShapeInfo.meShapeType)
767     {
768         case XmlShapeTypeDrawRectangleShape:
769         {
770             ImpExportRectangleShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
771             break;
772         }
773         case XmlShapeTypeDrawEllipseShape:
774         {
775             ImpExportEllipseShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
776             break;
777         }
778         case XmlShapeTypeDrawLineShape:
779         {
780             ImpExportLineShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
781             break;
782         }
783         case XmlShapeTypeDrawPolyPolygonShape:  // closed PolyPolygon
784         case XmlShapeTypeDrawPolyLineShape:     // open PolyPolygon
785         case XmlShapeTypeDrawClosedBezierShape: // closed PolyPolygon containing curves
786         case XmlShapeTypeDrawOpenBezierShape:   // open PolyPolygon containing curves
787         {
788             ImpExportPolygonShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
789             break;
790         }
791 
792         case XmlShapeTypeDrawTextShape:
793         case XmlShapeTypePresTitleTextShape:
794         case XmlShapeTypePresOutlinerShape:
795         case XmlShapeTypePresSubtitleShape:
796         case XmlShapeTypePresNotesShape:
797         case XmlShapeTypePresHeaderShape:
798         case XmlShapeTypePresFooterShape:
799         case XmlShapeTypePresSlideNumberShape:
800         case XmlShapeTypePresDateTimeShape:
801         {
802             ImpExportTextBoxShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
803             break;
804         }
805 
806         case XmlShapeTypeDrawGraphicObjectShape:
807         case XmlShapeTypePresGraphicObjectShape:
808         {
809             ImpExportGraphicObjectShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
810             break;
811         }
812 
813         case XmlShapeTypeDrawChartShape:
814         case XmlShapeTypePresChartShape:
815         {
816             ImpExportChartShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint, pAttrList );
817             break;
818         }
819 
820         case XmlShapeTypeDrawControlShape:
821         {
822             ImpExportControlShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
823             break;
824         }
825 
826         case XmlShapeTypeDrawConnectorShape:
827         {
828             ImpExportConnectorShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
829             break;
830         }
831 
832         case XmlShapeTypeDrawMeasureShape:
833         {
834             ImpExportMeasureShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
835             break;
836         }
837 
838         case XmlShapeTypeDrawOLE2Shape:
839         case XmlShapeTypePresOLE2Shape:
840         case XmlShapeTypeDrawSheetShape:
841         case XmlShapeTypePresSheetShape:
842         {
843             ImpExportOLE2Shape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
844             break;
845         }
846 
847         case XmlShapeTypePresTableShape:
848         case XmlShapeTypeDrawTableShape:
849         {
850             ImpExportTableShape( xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
851             break;
852         }
853 
854         case XmlShapeTypeDrawPageShape:
855         case XmlShapeTypePresPageShape:
856         case XmlShapeTypeHandoutShape:
857         {
858             ImpExportPageShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
859             break;
860         }
861 
862         case XmlShapeTypeDrawCaptionShape:
863         {
864             ImpExportCaptionShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
865             break;
866         }
867 
868         case XmlShapeTypeDraw3DCubeObject:
869         case XmlShapeTypeDraw3DSphereObject:
870         case XmlShapeTypeDraw3DLatheObject:
871         case XmlShapeTypeDraw3DExtrudeObject:
872         {
873             ImpExport3DShape(xShape, aShapeInfo.meShapeType);
874             break;
875         }
876 
877         case XmlShapeTypeDraw3DSceneObject:
878         {
879             ImpExport3DSceneShape( xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
880             break;
881         }
882 
883         case XmlShapeTypeDrawGroupShape:
884         {
885             // empty group
886             ImpExportGroupShape( xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
887             break;
888         }
889 
890         case XmlShapeTypeDrawFrameShape:
891         {
892             ImpExportFrameShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
893             break;
894         }
895 
896         case XmlShapeTypeDrawAppletShape:
897         {
898             ImpExportAppletShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
899             break;
900         }
901 
902         case XmlShapeTypeDrawPluginShape:
903         {
904             ImpExportPluginShape(xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
905             break;
906         }
907 
908         case XmlShapeTypeDrawCustomShape:
909         {
910             if ( aShapeInfo.xCustomShapeReplacement.is() )
911                 ImpExportGroupShape( aShapeInfo.xCustomShapeReplacement, XmlShapeTypeDrawGroupShape, nFeatures, pRefPoint );
912             else
913                 ImpExportCustomShape( xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
914             break;
915         }
916 
917         case XmlShapeTypePresMediaShape:
918         case XmlShapeTypeDrawMediaShape:
919         {
920             ImpExportMediaShape( xShape, aShapeInfo.meShapeType, nFeatures, pRefPoint );
921             break;
922         }
923 
924         case XmlShapeTypePresOrgChartShape:
925         case XmlShapeTypeUnknown:
926         case XmlShapeTypeNotYetSet:
927         default:
928         {
929             // this should never happen and is an error
930             DBG_ERROR("XMLEXP: WriteShape: unknown or unexpected type of shape in export!");
931             break;
932         }
933     }
934 
935     mpHyperlinkElement.reset();
936 
937     // #97489# #97111#
938     // if there was an error and no element for the shape was exported
939     // we need to clear the attribute list or the attributes will be
940     // set on the next exported element, which can result in corrupt
941     // xml files due to duplicate attributes
942 
943     mrExport.CheckAttrList();   // asserts in non pro if we have attributes left
944     mrExport.ClearAttrList();   // clears the attributes
945 }
946 
947 ///////////////////////////////////////////////////////////////////////
948 
949 // This method collects all automatic styles for the shapes inside the given XShapes collection
collectShapesAutoStyles(const uno::Reference<drawing::XShapes> & xShapes)950 void XMLShapeExport::collectShapesAutoStyles( const uno::Reference < drawing::XShapes >& xShapes )
951 {
952     ShapesInfos::iterator aOldCurrentShapesIter = maCurrentShapesIter;
953     seekShapes( xShapes );
954 
955     uno::Reference< drawing::XShape > xShape;
956     const sal_Int32 nShapeCount(xShapes->getCount());
957     for(sal_Int32 nShapeId = 0; nShapeId < nShapeCount; nShapeId++)
958     {
959         xShapes->getByIndex(nShapeId) >>= xShape;
960         DBG_ASSERT( xShape.is(), "Shape without a XShape?" );
961         if(!xShape.is())
962             continue;
963 
964         collectShapeAutoStyles( xShape );
965     }
966 
967     maCurrentShapesIter = aOldCurrentShapesIter;
968 }
969 
970 ///////////////////////////////////////////////////////////////////////
971 
972 // This method exports all XShape inside the given XShapes collection
exportShapes(const uno::Reference<drawing::XShapes> & xShapes,sal_Int32 nFeatures,awt::Point * pRefPoint)973 void XMLShapeExport::exportShapes( const uno::Reference < drawing::XShapes >& xShapes, sal_Int32 nFeatures /* = SEF_DEFAULT */, awt::Point* pRefPoint /* = NULL */ )
974 {
975     ShapesInfos::iterator aOldCurrentShapesIter = maCurrentShapesIter;
976     seekShapes( xShapes );
977 
978     uno::Reference< drawing::XShape > xShape;
979     const sal_Int32 nShapeCount(xShapes->getCount());
980     for(sal_Int32 nShapeId = 0; nShapeId < nShapeCount; nShapeId++)
981     {
982         xShapes->getByIndex(nShapeId) >>= xShape;
983         DBG_ASSERT( xShape.is(), "Shape without a XShape?" );
984         if(!xShape.is())
985             continue;
986 
987         exportShape( xShape, nFeatures, pRefPoint );
988     }
989 
990     maCurrentShapesIter = aOldCurrentShapesIter;
991 }
992 
993 ///////////////////////////////////////////////////////////////////////
994 
seekShapes(const uno::Reference<drawing::XShapes> & xShapes)995 void XMLShapeExport::seekShapes( const uno::Reference< drawing::XShapes >& xShapes ) throw()
996 {
997     if( xShapes.is() )
998     {
999         maCurrentShapesIter = maShapesInfos.find( xShapes );
1000         if( maCurrentShapesIter == maShapesInfos.end() )
1001         {
1002             ImplXMLShapeExportInfoVector aNewInfoVector;
1003             aNewInfoVector.resize( (ShapesInfos::size_type) xShapes->getCount() );
1004             maShapesInfos[ xShapes ] = aNewInfoVector;
1005 
1006             maCurrentShapesIter = maShapesInfos.find( xShapes );
1007 
1008             DBG_ASSERT( maCurrentShapesIter != maShapesInfos.end(), "XMLShapeExport::seekShapes(): insert into stl::map failed" );
1009         }
1010 
1011         DBG_ASSERT( (*maCurrentShapesIter).second.size() == (ShapesInfos::size_type)xShapes->getCount(), "XMLShapeExport::seekShapes(): XShapes size varied between calls" );
1012 
1013     }
1014     else
1015     {
1016         maCurrentShapesIter = maShapesInfos.end();
1017     }
1018 }
1019 
1020 ///////////////////////////////////////////////////////////////////////
1021 
exportAutoStyles()1022 void XMLShapeExport::exportAutoStyles()
1023 {
1024     // export all autostyle infos
1025 
1026     // ...for graphic
1027 //  if(IsFamilyGraphicUsed())
1028     {
1029         GetExport().GetAutoStylePool()->exportXML(
1030             XML_STYLE_FAMILY_SD_GRAPHICS_ID
1031             , GetExport().GetDocHandler(),
1032             GetExport().GetMM100UnitConverter(),
1033             GetExport().GetNamespaceMap()
1034             );
1035     }
1036 
1037     // ...for presentation
1038 //  if(IsFamilyPresentationUsed())
1039     {
1040         GetExport().GetAutoStylePool()->exportXML(
1041             XML_STYLE_FAMILY_SD_PRESENTATION_ID
1042             , GetExport().GetDocHandler(),
1043             GetExport().GetMM100UnitConverter(),
1044             GetExport().GetNamespaceMap()
1045             );
1046     }
1047 
1048     if( mxShapeTableExport.is() )
1049         mxShapeTableExport->exportAutoStyles();
1050 }
1051 
1052 ///////////////////////////////////////////////////////////////////////
1053 
1054 /// returns the export property mapper for external chaining
CreateShapePropMapper(SvXMLExport & rExport)1055 SvXMLExportPropertyMapper* XMLShapeExport::CreateShapePropMapper(
1056     SvXMLExport& rExport )
1057 {
1058     UniReference< XMLPropertyHandlerFactory > xFactory = new XMLSdPropHdlFactory( rExport.GetModel(), rExport );
1059     UniReference < XMLPropertySetMapper > xMapper = new XMLShapePropertySetMapper( xFactory );
1060     SvXMLExportPropertyMapper* pResult =
1061         new XMLShapeExportPropertyMapper( xMapper,
1062                                           (XMLTextListAutoStylePool*)&rExport.GetTextParagraphExport()->GetListAutoStylePool(),
1063                                           rExport );
1064     // chain text attributes
1065     return pResult;
1066 }
1067 
1068 ///////////////////////////////////////////////////////////////////////
1069 
ImpCalcShapeType(const uno::Reference<drawing::XShape> & xShape,XmlShapeType & eShapeType)1070 void XMLShapeExport::ImpCalcShapeType(const uno::Reference< drawing::XShape >& xShape,
1071     XmlShapeType& eShapeType)
1072 {
1073     // set in every case, so init here
1074     eShapeType = XmlShapeTypeUnknown;
1075 
1076     uno::Reference< drawing::XShapeDescriptor > xShapeDescriptor(xShape, uno::UNO_QUERY);
1077     if(xShapeDescriptor.is())
1078     {
1079         String aType((OUString)xShapeDescriptor->getShapeType());
1080 
1081         if(aType.EqualsAscii((const sal_Char*)"com.sun.star.", 0, 13))
1082         {
1083             if(aType.EqualsAscii("drawing.", 13, 8))
1084             {
1085                 // drawing shapes
1086                 if     (aType.EqualsAscii("Rectangle", 21, 9)) { eShapeType = XmlShapeTypeDrawRectangleShape; }
1087 
1088                 // #i72177# Note: Correcting CustomShape, CustomShape->Custom, len from 9 (was wrong anyways) to 6.
1089                 // As can be seen at the other compares, the appendix "Shape" is left out of the comparison.
1090                 else if(aType.EqualsAscii("Custom", 21, 6)) { eShapeType = XmlShapeTypeDrawCustomShape; }
1091 
1092                 else if(aType.EqualsAscii("Ellipse", 21, 7)) { eShapeType = XmlShapeTypeDrawEllipseShape; }
1093                 else if(aType.EqualsAscii("Control", 21, 7)) { eShapeType = XmlShapeTypeDrawControlShape; }
1094                 else if(aType.EqualsAscii("Connector", 21, 9)) { eShapeType = XmlShapeTypeDrawConnectorShape; }
1095                 else if(aType.EqualsAscii("Measure", 21, 7)) { eShapeType = XmlShapeTypeDrawMeasureShape; }
1096                 else if(aType.EqualsAscii("Line", 21, 4)) { eShapeType = XmlShapeTypeDrawLineShape; }
1097 
1098                 // #i72177# Note: This covers two types by purpose, PolyPolygonShape and PolyPolygonPathShape
1099                 else if(aType.EqualsAscii("PolyPolygon", 21, 11)) { eShapeType = XmlShapeTypeDrawPolyPolygonShape; }
1100 
1101                 // #i72177# Note: This covers two types by purpose, PolyLineShape and PolyLinePathShape
1102                 else if(aType.EqualsAscii("PolyLine", 21, 8)) { eShapeType = XmlShapeTypeDrawPolyLineShape; }
1103 
1104                 else if(aType.EqualsAscii("OpenBezier", 21, 10)) { eShapeType = XmlShapeTypeDrawOpenBezierShape; }
1105                 else if(aType.EqualsAscii("ClosedBezier", 21, 12)) { eShapeType = XmlShapeTypeDrawClosedBezierShape; }
1106 
1107                 // #i72177# FreeHand (opened and closed) now supports the types OpenFreeHandShape and
1108                 // ClosedFreeHandShape respectively. Represent them as bezier shapes
1109                 else if(aType.EqualsAscii("OpenFreeHand", 21, 12)) { eShapeType = XmlShapeTypeDrawOpenBezierShape; }
1110                 else if(aType.EqualsAscii("ClosedFreeHand", 21, 14)) { eShapeType = XmlShapeTypeDrawClosedBezierShape; }
1111 
1112                 else if(aType.EqualsAscii("GraphicObject", 21, 13)) { eShapeType = XmlShapeTypeDrawGraphicObjectShape; }
1113                 else if(aType.EqualsAscii("Group", 21, 5)) { eShapeType = XmlShapeTypeDrawGroupShape; }
1114                 else if(aType.EqualsAscii("Text", 21, 4)) { eShapeType = XmlShapeTypeDrawTextShape; }
1115                 else if(aType.EqualsAscii("OLE2", 21, 4))
1116                 {
1117                     eShapeType = XmlShapeTypeDrawOLE2Shape;
1118 
1119                     // get info about presentation shape
1120                     uno::Reference <beans::XPropertySet> xPropSet(xShape, uno::UNO_QUERY);
1121 
1122                     if(xPropSet.is())
1123                     {
1124                         rtl::OUString sCLSID;
1125                         if(xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CLSID"))) >>= sCLSID)
1126                         {
1127                             if (sCLSID.equals(mrExport.GetChartExport()->getChartCLSID()))
1128                             {
1129                                 eShapeType = XmlShapeTypeDrawChartShape;
1130                             }
1131                             else if (
1132                                 sCLSID.equals(rtl::OUString( SvGlobalName( SO3_SC_CLASSID ).GetHexName()))
1133                                 // #110680#
1134                                 // same reaction for binfilter
1135                                 || sCLSID.equals(rtl::OUString( SvGlobalName( BF_SO3_SC_CLASSID ).GetHexName()))
1136                                 // #121222#
1137                                 // same reaction for graph in report builder
1138                                 || sCLSID.equals(rtl::OUString( SvGlobalName( SO3_RPT_SCH_CLASSID_90 ).GetHexName()))
1139                                 )
1140                             {
1141                                 eShapeType = XmlShapeTypeDrawSheetShape;
1142                             }
1143                             else
1144                             {
1145                                 // general OLE2 Object
1146                             }
1147                         }
1148                     }
1149                 }
1150                 else if(aType.EqualsAscii("Page", 21, 4)) { eShapeType = XmlShapeTypeDrawPageShape; }
1151                 else if(aType.EqualsAscii("Frame", 21, 5)) { eShapeType = XmlShapeTypeDrawFrameShape; }
1152                 else if(aType.EqualsAscii("Caption", 21, 7)) { eShapeType = XmlShapeTypeDrawCaptionShape; }
1153                 else if(aType.EqualsAscii("Plugin", 21, 6)) { eShapeType = XmlShapeTypeDrawPluginShape; }
1154                 else if(aType.EqualsAscii("Applet", 21, 6)) { eShapeType = XmlShapeTypeDrawAppletShape; }
1155                 else if(aType.EqualsAscii("MediaShape", 21, 10)) { eShapeType = XmlShapeTypeDrawMediaShape; }
1156                 else if(aType.EqualsAscii("TableShape", 21, 10)) { eShapeType = XmlShapeTypeDrawTableShape; }
1157 
1158                 // 3D shapes
1159                 else if(aType.EqualsAscii("Scene", 21 + 7, 5)) { eShapeType = XmlShapeTypeDraw3DSceneObject; }
1160                 else if(aType.EqualsAscii("Cube", 21 + 7, 4)) { eShapeType = XmlShapeTypeDraw3DCubeObject; }
1161                 else if(aType.EqualsAscii("Sphere", 21 + 7, 6)) { eShapeType = XmlShapeTypeDraw3DSphereObject; }
1162                 else if(aType.EqualsAscii("Lathe", 21 + 7, 5)) { eShapeType = XmlShapeTypeDraw3DLatheObject; }
1163                 else if(aType.EqualsAscii("Extrude", 21 + 7, 7)) { eShapeType = XmlShapeTypeDraw3DExtrudeObject; }
1164             }
1165             else if(aType.EqualsAscii("presentation.", 13, 13))
1166             {
1167                 // presentation shapes
1168                 if     (aType.EqualsAscii("TitleText", 26, 9)) { eShapeType = XmlShapeTypePresTitleTextShape; }
1169                 else if(aType.EqualsAscii("Outliner", 26, 8)) { eShapeType = XmlShapeTypePresOutlinerShape;  }
1170                 else if(aType.EqualsAscii("Subtitle", 26, 8)) { eShapeType = XmlShapeTypePresSubtitleShape;  }
1171                 else if(aType.EqualsAscii("GraphicObject", 26, 13)) { eShapeType = XmlShapeTypePresGraphicObjectShape;  }
1172                 else if(aType.EqualsAscii("Page", 26, 4)) { eShapeType = XmlShapeTypePresPageShape;  }
1173                 else if(aType.EqualsAscii("OLE2", 26, 4))
1174                 {
1175                     eShapeType = XmlShapeTypePresOLE2Shape;
1176 
1177                     // get info about presentation shape
1178                     uno::Reference <beans::XPropertySet> xPropSet(xShape, uno::UNO_QUERY);
1179 
1180                     if(xPropSet.is()) try
1181                     {
1182                         rtl::OUString sCLSID;
1183                         if(xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CLSID"))) >>= sCLSID)
1184                         {
1185                             if( sCLSID.equals(rtl::OUString( SvGlobalName( SO3_SC_CLASSID ).GetHexName())) ||
1186                                 sCLSID.equals(rtl::OUString( SvGlobalName( BF_SO3_SC_CLASSID ).GetHexName())) )
1187                             {
1188                                 eShapeType = XmlShapeTypePresSheetShape;
1189                             }
1190                         }
1191                     }
1192                     catch( uno::Exception& )
1193                     {
1194                         DBG_ERROR( "XMLShapeExport::ImpCalcShapeType(), expected ole shape to have the CLSID property?" );
1195                     }
1196                 }
1197                 else if(aType.EqualsAscii("Chart", 26, 5)) { eShapeType = XmlShapeTypePresChartShape;  }
1198                 else if(aType.EqualsAscii("OrgChart", 26, 8)) { eShapeType = XmlShapeTypePresOrgChartShape;  }
1199                 else if(aType.EqualsAscii("CalcShape", 26, 9)) { eShapeType = XmlShapeTypePresSheetShape; }
1200                 else if(aType.EqualsAscii("TableShape", 26, 10)) { eShapeType = XmlShapeTypePresTableShape; }
1201                 else if(aType.EqualsAscii("Notes", 26, 5)) { eShapeType = XmlShapeTypePresNotesShape;  }
1202                 else if(aType.EqualsAscii("HandoutShape", 26, 12)) { eShapeType = XmlShapeTypeHandoutShape; }
1203                 else if(aType.EqualsAscii("HeaderShape", 26, 11)) { eShapeType = XmlShapeTypePresHeaderShape; }
1204                 else if(aType.EqualsAscii("FooterShape", 26, 11)) { eShapeType = XmlShapeTypePresFooterShape; }
1205                 else if(aType.EqualsAscii("SlideNumberShape", 26, 16)) { eShapeType = XmlShapeTypePresSlideNumberShape; }
1206                 else if(aType.EqualsAscii("DateTimeShape", 26, 13)) { eShapeType = XmlShapeTypePresDateTimeShape; }
1207                 else if(aType.EqualsAscii("MediaShape", 26, 10)) { eShapeType = XmlShapeTypePresMediaShape; }
1208             }
1209         }
1210     }
1211 }
1212 
1213 ///////////////////////////////////////////////////////////////////////
1214 
1215 extern SvXMLEnumMapEntry aXML_GlueAlignment_EnumMap[];
1216 extern SvXMLEnumMapEntry aXML_GlueEscapeDirection_EnumMap[];
1217 
1218 /** exports all user defined glue points */
ImpExportGluePoints(const uno::Reference<drawing::XShape> & xShape)1219 void XMLShapeExport::ImpExportGluePoints( const uno::Reference< drawing::XShape >& xShape )
1220 {
1221     uno::Reference< drawing::XGluePointsSupplier > xSupplier( xShape, uno::UNO_QUERY );
1222     if( !xSupplier.is() )
1223         return;
1224 
1225     uno::Reference< container::XIdentifierAccess > xGluePoints( xSupplier->getGluePoints(), uno::UNO_QUERY );
1226     if( !xGluePoints.is() )
1227         return;
1228 
1229     drawing::GluePoint2 aGluePoint;
1230 
1231     uno::Sequence< sal_Int32 > aIdSequence( xGluePoints->getIdentifiers() );
1232 
1233     const sal_Int32 nCount = aIdSequence.getLength();
1234     for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
1235     {
1236         const sal_Int32 nIdentifier = aIdSequence[nIndex];
1237         if( (xGluePoints->getByIdentifier( nIdentifier ) >>= aGluePoint) && aGluePoint.IsUserDefined )
1238         {
1239             // export only user defined glue points
1240 
1241             const OUString sId( OUString::valueOf( nIdentifier ) );
1242             mrExport.AddAttribute(XML_NAMESPACE_DRAW, XML_ID, sId );
1243 
1244             mrExport.GetMM100UnitConverter().convertMeasure(msBuffer, aGluePoint.Position.X);
1245             mrExport.AddAttribute(XML_NAMESPACE_SVG, XML_X, msBuffer.makeStringAndClear());
1246 
1247             mrExport.GetMM100UnitConverter().convertMeasure(msBuffer, aGluePoint.Position.Y);
1248             mrExport.AddAttribute(XML_NAMESPACE_SVG, XML_Y, msBuffer.makeStringAndClear());
1249 
1250             if( !aGluePoint.IsRelative )
1251             {
1252                 SvXMLUnitConverter::convertEnum( msBuffer, aGluePoint.PositionAlignment, aXML_GlueAlignment_EnumMap );
1253                 mrExport.AddAttribute( XML_NAMESPACE_DRAW, XML_ALIGN, msBuffer.makeStringAndClear() );
1254             }
1255 
1256             // required by the schema, so SMART ("auto") is written too
1257             SvXMLUnitConverter::convertEnum( msBuffer, aGluePoint.Escape, aXML_GlueEscapeDirection_EnumMap );
1258             mrExport.AddAttribute( XML_NAMESPACE_DRAW, XML_ESCAPE_DIRECTION, msBuffer.makeStringAndClear() );
1259 
1260             SvXMLElementExport aEventsElemt(mrExport, XML_NAMESPACE_DRAW, XML_GLUE_POINT, sal_True, sal_True);
1261         }
1262     }
1263 }
1264 
ExportGraphicDefaults()1265 void XMLShapeExport::ExportGraphicDefaults()
1266 {
1267     XMLStyleExport aStEx(mrExport, OUString(), mrExport.GetAutoStylePool().get());
1268 
1269     // construct PropertySetMapper
1270     UniReference< SvXMLExportPropertyMapper > xPropertySetMapper( CreateShapePropMapper( mrExport ) );
1271     ((XMLShapeExportPropertyMapper*)xPropertySetMapper.get())->SetAutoStyles( sal_False );
1272 
1273     // chain text attributes
1274     xPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaExtPropMapper(mrExport));
1275 
1276     // chain special Writer/text frame default attributes
1277     xPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaDefaultExtPropMapper(mrExport));
1278 
1279     // write graphic family default style
1280     uno::Reference< lang::XMultiServiceFactory > xFact( mrExport.GetModel(), uno::UNO_QUERY );
1281     if( xFact.is() )
1282     {
1283         try
1284         {
1285             uno::Reference< beans::XPropertySet > xDefaults( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Defaults") ) ), uno::UNO_QUERY );
1286             if( xDefaults.is() )
1287             {
1288                 aStEx.exportDefaultStyle( xDefaults, OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME)), xPropertySetMapper );
1289 
1290                 // write graphic family styles
1291                 aStEx.exportStyleFamily("graphics", OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME)), xPropertySetMapper, sal_False, XML_STYLE_FAMILY_SD_GRAPHICS_ID);
1292             }
1293         }
1294         catch( lang::ServiceNotRegisteredException& )
1295         {
1296         }
1297     }
1298 }
1299 
onExport(const com::sun::star::uno::Reference<com::sun::star::drawing::XShape> &)1300 void XMLShapeExport::onExport( const com::sun::star::uno::Reference < com::sun::star::drawing::XShape >& )
1301 {
1302 }
1303 
GetShapeTableExport()1304 const rtl::Reference< XMLTableExport >& XMLShapeExport::GetShapeTableExport()
1305 {
1306     if( !mxShapeTableExport.is() )
1307     {
1308         rtl::Reference< XMLPropertyHandlerFactory > xFactory( new XMLSdPropHdlFactory( mrExport.GetModel(), mrExport ) );
1309         UniReference < XMLPropertySetMapper > xMapper( new XMLShapePropertySetMapper( xFactory.get() ) );
1310         rtl::Reference< SvXMLExportPropertyMapper > xPropertySetMapper( new XMLShapeExportPropertyMapper( xMapper, (XMLTextListAutoStylePool*)&mrExport.GetTextParagraphExport()->GetListAutoStylePool(), mrExport ) );
1311         mxShapeTableExport = new XMLTableExport( mrExport, xPropertySetMapper, xFactory );
1312     }
1313 
1314     return mxShapeTableExport;
1315 }
1316