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