[Libreoffice-commits] core.git: include/svx svl/source svx/source

Armin Le Grand alg at apache.org
Tue Apr 30 07:40:39 PDT 2013


 include/svx/svdundo.hxx       |   11 +++++---
 svl/source/items/style.cxx    |   21 ++++++++++------
 svx/source/svdraw/svdundo.cxx |   53 ++++++++++++++++++++++++++++++++++--------
 3 files changed, 63 insertions(+), 22 deletions(-)

New commits:
commit 4c8ffa01131f2df2b314218731d83bd776944802
Author: Armin Le Grand <alg at apache.org>
Date:   Wed Jun 20 08:17:23 2012 +0000

    i#120015# Let SdrUndoAttrObj remember a reference to the used style to survive
    
    removal of the style by UI (which creates no undo actions). Re-add the
    style when undoing if needed.
    
    Change-Id: I6069a1cb42dfaeb0dd35fdc15687fd307f2b641e

diff --git a/include/svx/svdundo.hxx b/include/svx/svdundo.hxx
index 2221164..78d9a9c 100644
--- a/include/svx/svdundo.hxx
+++ b/include/svx/svdundo.hxx
@@ -22,8 +22,9 @@
 
 #include <svl/solar.hrc>
 #include <svl/undo.hxx>
+#include <svl/style.hxx>
 #include <tools/gen.hxx>
-#include <svx/svdtypes.hxx> // fuer enum RepeatFuncts
+#include <svx/svdtypes.hxx> // for enum RepeatFuncts
 #include <svx/svdsob.hxx>
 #include "svx/svxdllapi.h"
 
@@ -159,9 +160,8 @@ protected:
     SfxItemSet*                 pRepeatSet;
 
     // oder besser den StyleSheetNamen merken?
-    SfxStyleSheet*              pUndoStyleSheet;
-    SfxStyleSheet*              pRedoStyleSheet;
-    SfxStyleSheet*              pRepeatStyleSheet;
+    rtl::Reference< SfxStyleSheetBase > mxUndoStyleSheet;
+    rtl::Reference< SfxStyleSheetBase > mxRedoStyleSheet;
     bool                        bStyleSheet;
     bool                        bHaveToTakeRedoSet;
 
@@ -174,6 +174,9 @@ protected:
     // Wenn sich um ein Gruppenobjekt handelt:
     SdrUndoGroup*               pUndoGroup;
 
+    // helper to ensure StyleSheet is in pool (provided by SdrModel from SdrObject)
+    void ensureStyleSheetInStyleSheetPool(SfxStyleSheetBasePool& rStyleSheetPool, SfxStyleSheet& rSheet);
+
 public:
     SdrUndoAttrObj(SdrObject& rNewObj, bool bStyleSheet1 = false, bool bSaveText = false);
     virtual ~SdrUndoAttrObj();
diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx
index c2879e7..8c8c193 100644
--- a/svl/source/items/style.cxx
+++ b/svl/source/items/style.cxx
@@ -734,14 +734,19 @@ void SfxStyleSheetBasePool::Remove( SfxStyleSheetBase* p )
             // Alle Styles umsetzen, deren Parent dieser hier ist
             ChangeParent( p->GetName(), p->GetParent() );
 
-            com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY );
-            if( xComp.is() ) try
-            {
-                xComp->dispose();
-            }
-            catch( com::sun::star::uno::Exception& )
-            {
-            }
+            // #120015# Do not dispose, the removed StyleSheet may still be used in
+            // existing SdrUndoAttrObj incarnations. Rely on refcounting for disposal,
+            // this works well under normal conditions (checked breaking and counting
+            // on SfxStyleSheetBase constructors and destructors)
+            //
+            // com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY );
+            // if( xComp.is() ) try
+            // {
+            //  xComp->dispose();
+            // }
+            // catch( com::sun::star::uno::Exception& )
+            // {
+            // }
 
             aStyles.erase(aIter);
             Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *p ) );
diff --git a/svx/source/svdraw/svdundo.cxx b/svx/source/svdraw/svdundo.cxx
index 284aaca..3bcace5 100644
--- a/svx/source/svdraw/svdundo.cxx
+++ b/svx/source/svdraw/svdundo.cxx
@@ -246,16 +246,29 @@ void SdrUndoObj::ImpShowPageOfThisObject()
     }
 }
 
-////////////////////////////////////////////////////////////////////////////////////////////////////
+void SdrUndoAttrObj::ensureStyleSheetInStyleSheetPool(SfxStyleSheetBasePool& rStyleSheetPool, SfxStyleSheet& rSheet)
+{
+    SfxStyleSheetBase* pThere = rStyleSheetPool.Find(rSheet.GetName(), rSheet.GetFamily());
+
+    if(!pThere)
+    {
+        // re-insert remembered style which was removed in the meantime. To do this
+        // without assertion, do it without parent and set parent after insertion
+        const UniString aParent(rSheet.GetParent());
+
+        rSheet.SetParent(UniString());
+        rStyleSheetPool.Insert(&rSheet);
+        rSheet.SetParent(aParent);
+    }
+}
 
 SdrUndoAttrObj::SdrUndoAttrObj(SdrObject& rNewObj, bool bStyleSheet1, bool bSaveText)
 :   SdrUndoObj(rNewObj),
     pUndoSet(NULL),
     pRedoSet(NULL),
     pRepeatSet(NULL),
-    pUndoStyleSheet(NULL),
-    pRedoStyleSheet(NULL),
-    pRepeatStyleSheet(NULL),
+    mxUndoStyleSheet(),
+    mxRedoStyleSheet(),
     bHaveToTakeRedoSet(sal_True),
     pTextUndo(NULL),
 
@@ -288,7 +301,7 @@ SdrUndoAttrObj::SdrUndoAttrObj(SdrObject& rNewObj, bool bStyleSheet1, bool bSave
         pUndoSet = new SfxItemSet(pObj->GetMergedItemSet());
 
         if(bStyleSheet)
-            pUndoStyleSheet = pObj->GetStyleSheet();
+            mxUndoStyleSheet = pObj->GetStyleSheet();
 
         if(bSaveText)
         {
@@ -330,7 +343,7 @@ void SdrUndoAttrObj::Undo()
             pRedoSet = new SfxItemSet(pObj->GetMergedItemSet());
 
             if(bStyleSheet)
-                pRedoStyleSheet=pObj->GetStyleSheet();
+                mxRedoStyleSheet = pObj->GetStyleSheet();
 
             if(pTextUndo)
             {
@@ -344,8 +357,18 @@ void SdrUndoAttrObj::Undo()
 
         if(bStyleSheet)
         {
-            pRedoStyleSheet = pObj->GetStyleSheet();
-            pObj->SetStyleSheet(pUndoStyleSheet, sal_True);
+            mxRedoStyleSheet = pObj->GetStyleSheet();
+            SfxStyleSheet* pSheet = dynamic_cast< SfxStyleSheet* >(mxUndoStyleSheet.get());
+
+            if(pSheet && pObj->GetModel() && pObj->GetModel()->GetStyleSheetPool())
+            {
+                ensureStyleSheetInStyleSheetPool(*pObj->GetModel()->GetStyleSheetPool(), *pSheet);
+                pObj->SetStyleSheet(pSheet, sal_True);
+            }
+            else
+            {
+                OSL_ENSURE(false, "OOps, something went wrong in SdrUndoAttrObj (!)");
+            }
         }
 
         sdr::properties::ItemChangeBroadcaster aItemChange(*pObj);
@@ -417,8 +440,18 @@ void SdrUndoAttrObj::Redo()
     {
         if(bStyleSheet)
         {
-            pUndoStyleSheet = pObj->GetStyleSheet();
-            pObj->SetStyleSheet(pRedoStyleSheet, sal_True);
+            mxUndoStyleSheet = pObj->GetStyleSheet();
+            SfxStyleSheet* pSheet = dynamic_cast< SfxStyleSheet* >(mxRedoStyleSheet.get());
+
+            if(pSheet && pObj->GetModel() && pObj->GetModel()->GetStyleSheetPool())
+            {
+                ensureStyleSheetInStyleSheetPool(*pObj->GetModel()->GetStyleSheetPool(), *pSheet);
+                pObj->SetStyleSheet(pSheet, sal_True);
+            }
+            else
+            {
+                OSL_ENSURE(false, "OOps, something went wrong in SdrUndoAttrObj (!)");
+            }
         }
 
         sdr::properties::ItemChangeBroadcaster aItemChange(*pObj);


More information about the Libreoffice-commits mailing list