[Libreoffice-commits] core.git: Branch 'libreoffice-4-1' - include/xmloff xmloff/source

Michael Stahl mstahl at redhat.com
Wed Sep 4 01:40:23 PDT 2013


 include/xmloff/xmlmultiimagehelper.hxx     |    2 -
 xmloff/source/core/xmlmultiimagehelper.cxx |    4 +--
 xmloff/source/draw/ximpshap.cxx            |    5 ++--
 xmloff/source/text/XMLTextFrameContext.cxx |   30 +++++++++++++++++++++++++++--
 4 files changed, 34 insertions(+), 7 deletions(-)

New commits:
commit 11c465ef8205cf946b3c0810f7305fa9dd6c0bc0
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue Sep 3 00:32:08 2013 +0200

    fdo#68839: ODF import: fix name of multi-image frame
    
    When multiple image child elements are inside a frame, each one is
    imported and gets unique name via SwDoc::SetFlyName().  But the
    retained one is not necessarily the first one, which is the only one
    that may have the original name.
    
    Also the solveMultipleImages needs to return a smart pointer, as nothing
    else keeps the image contexts alive.
    
    (regression from 44cfc7cb6533d827fd2d6e586d92c61d7d7f7a70)
    
    Change-Id: I28a8a752f3eed176cc2ebb4c9af11a0dd4d18ea6
    (cherry picked from commit b69d152cfa1da868ba960345d72ba78f9f8e1b35)
    Reviewed-on: https://gerrit.libreoffice.org/5777
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/xmloff/xmlmultiimagehelper.hxx b/include/xmloff/xmlmultiimagehelper.hxx
index 7a7e2ab..050eff7 100644
--- a/include/xmloff/xmlmultiimagehelper.hxx
+++ b/include/xmloff/xmlmultiimagehelper.hxx
@@ -44,7 +44,7 @@ public:
     /// see imlementation for evtl. changing weights and/or adding filetypes.
     ///
     /// @returns import context of the selected image
-    const SvXMLImportContext* solveMultipleImages();
+    SvXMLImportContextRef solveMultipleImages();
 
     /// add a content to the remembered image import contexts
     void addContent(const SvXMLImportContext& rSvXMLImportContext);
diff --git a/xmloff/source/core/xmlmultiimagehelper.cxx b/xmloff/source/core/xmlmultiimagehelper.cxx
index 5159720..98aaef7 100644
--- a/xmloff/source/core/xmlmultiimagehelper.cxx
+++ b/xmloff/source/core/xmlmultiimagehelper.cxx
@@ -89,9 +89,9 @@ MultiImageImportHelper::~MultiImageImportHelper()
     }
 }
 
-const SvXMLImportContext* MultiImageImportHelper::solveMultipleImages()
+SvXMLImportContextRef MultiImageImportHelper::solveMultipleImages()
 {
-    const SvXMLImportContext* pContext(0);
+    SvXMLImportContextRef pContext;
     if(maImplContextVector.size() > 1)
     {
         // multiple child contexts were imported, decide which is the most valuable one
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index 1906703..b8d3deb 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -3566,8 +3566,9 @@ void SdXMLFrameShapeContext::StartElement(const uno::Reference< xml::sax::XAttri
 void SdXMLFrameShapeContext::EndElement()
 {
     // solve if multiple image child contexts were imported
-    const SvXMLImportContext* const pSelectedContext(solveMultipleImages());
-    const SdXMLGraphicObjectShapeContext* pShapeContext( dynamic_cast<const SdXMLGraphicObjectShapeContext*>( pSelectedContext ) );
+    SvXMLImportContextRef const pSelectedContext(solveMultipleImages());
+    const SdXMLGraphicObjectShapeContext* pShapeContext(
+        dynamic_cast<const SdXMLGraphicObjectShapeContext*>(&pSelectedContext));
     if ( pShapeContext && !maShapeId.isEmpty() )
     {
         // fdo#64512 and fdo#60075 - make sure *this* shape is
diff --git a/xmloff/source/text/XMLTextFrameContext.cxx b/xmloff/source/text/XMLTextFrameContext.cxx
index 4c268e6..3ca7e86 100644
--- a/xmloff/source/text/XMLTextFrameContext.cxx
+++ b/xmloff/source/text/XMLTextFrameContext.cxx
@@ -370,6 +370,7 @@ class XMLTextFrameContext_Impl : public SvXMLImportContext
     const OUString sTextBoxServiceName;
     const OUString sGraphicServiceName;
 
+    OUString m_sOrigName;
     OUString sName;
     OUString sStyleName;
     OUString sNextName;
@@ -447,6 +448,8 @@ public:
 
     void SetDesc( const OUString& rDesc );
 
+    void SetName();
+
     ::com::sun::star::text::TextContentAnchorType GetAnchorType() const { return eAnchorType; }
 
     const ::com::sun::star::uno::Reference <
@@ -901,6 +904,7 @@ XMLTextFrameContext_Impl::XMLTextFrameContext_Impl(
             sStyleName = rValue;
             break;
         case XML_TOK_TEXT_FRAME_NAME:
+            m_sOrigName = rValue;
             sName = rValue;
             break;
         case XML_TOK_TEXT_FRAME_FRAME_NAME:
@@ -1284,6 +1288,19 @@ void XMLTextFrameContext_Impl::SetHyperlink( const OUString& rHRef,
     }
 }
 
+void XMLTextFrameContext_Impl::SetName()
+{
+    Reference<XNamed> xNamed(xPropSet, UNO_QUERY);
+    if (xNamed.is())
+    {
+        OUString const name(xNamed->getName());
+        if (name != m_sOrigName)
+        {
+            xNamed->setName(m_sOrigName);
+        }
+    }
+}
+
 // Implement Title/Description Elements UI (#i73249#)
 void XMLTextFrameContext_Impl::SetTitle( const OUString& rTitle )
 {
@@ -1393,14 +1410,23 @@ XMLTextFrameContext::~XMLTextFrameContext()
 void XMLTextFrameContext::EndElement()
 {
     /// solve if multiple image child contexts were imported
-    solveMultipleImages();
+    SvXMLImportContextRef const pMultiContext(solveMultipleImages());
 
-    SvXMLImportContext *pContext = &m_xImplContext;
+    SvXMLImportContext const*const pContext =
+        (pMultiContext) ? &pMultiContext : &m_xImplContext;
     XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
+    assert(!pMultiContext || pImpl);
     if( pImpl )
     {
         pImpl->CreateIfNotThere();
 
+        // fdo#68839: in case the surviving image was not the first one,
+        // it will have a counter added to its name - set the original name
+        if (pMultiContext) // do this only when necessary; esp. not for text
+        {                  // frames that may have entries in GetRenameMap()!
+            pImpl->SetName();
+        }
+
         if( !m_sTitle.isEmpty() )
         {
             pImpl->SetTitle( m_sTitle );


More information about the Libreoffice-commits mailing list