Commits

Eike Rathke [er]  committed c077bf8

calcdatatables: DataTables undo of style deletion

  • Participants
  • Parent commits cd92c28

Comments (0)

Files changed (10)

File sc/inc/datatablestyle.hxx

 
 class ScDataTableFormatList : public ScDataTableFormats_Impl
 {
-public:
-        ScDataTableFormatList() {}
-        ScDataTableFormatList( const ScDataTableFormatList& rList );
-        ScDataTableFormatList( const ScDocument* pNewDoc, const ScDataTableFormatList& rList );
-        ~ScDataTableFormatList() {}
+    public:
+                ScDataTableFormatList() {}
+                ScDataTableFormatList( const ScDataTableFormatList& rList );
+                ScDataTableFormatList( const ScDocument* pNewDoc, const ScDataTableFormatList& rList );
+        virtual ~ScDataTableFormatList() {}
 
-    void    InsertNew( ScDataTableFormat* pNew )
-                { if (!Insert(pNew)) delete pNew; }
+        void    SetList( const ScDataTableFormatList& rList, const ScDocument* pNewDoc );
 
-    ScDataTableFormat* GetFormat( sal_uInt32 nKey );
+        void    InsertNew( ScDataTableFormat* pNew )
+                    { if (!Insert(pNew)) delete pNew; }
 
-    void    UpdateReference( UpdateRefMode eUpdateRefMode,
-                                const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
-    void    UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
-    void    RenameCellStyle( const String& rOld, const String& rNew );
-    bool    IsStyleSheetUsed( const ScStyleSheet& rStyle, bool bGatherAllStyles ) const;
-    void    InvalidateStyleSheet( const SfxStyleSheetBase* pStyleSheet );
+        ScDataTableFormat* GetFormat( sal_uInt32 nKey );
 
-    bool    operator==( const ScDataTableFormatList& r ) const;     // for Ref-Undo
+        void    UpdateReference( UpdateRefMode eUpdateRefMode,
+                    const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
+        void    UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
+        void    RenameCellStyle( const String& rOld, const String& rNew );
+        bool    IsStyleSheetUsed( const ScStyleSheet& rStyle, bool bGatherAllStyles ) const;
+        void    InvalidateStyleSheet( const SfxStyleSheetBase* pStyleSheet );
 };
 
 #endif

File sc/inc/document.hxx

 	ScValidationDataList* GetValidationList() const
 					{ return pValidationList; }
 
-    ScDataTableFormatList* GetDataTableFormatList() const { return pDataTableFormatList; }
+    ScDataTableFormatList*      GetDataTableFormatList() const { return pDataTableFormatList; }
+    void                        SetDataTableFormatList( const ScDataTableFormatList& rList );
 	SC_DLLPUBLIC ULONG			AddDataTableFormat( const ScDataTableFormat& rNew );
     SC_DLLPUBLIC const SfxItemSet* GetDataTableItemSet( SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt32 nKey = 0 ) const;
 

File sc/source/core/data/datatablestyle.cxx

     :
         ScDataTableFormats_Impl()
 {
-    size_t nCount = rList.Count();
-    for (size_t i=0; i<nCount; i++)
-        InsertNew( new ScDataTableFormat( *rList[i], NULL));
+    SetList( rList, NULL);
 }
 
 
 ScDataTableFormatList::ScDataTableFormatList( const ScDocument* pNewDoc, const ScDataTableFormatList& rList )
+    :
+        ScDataTableFormats_Impl()
 {
+    SetList( rList, pNewDoc);
+}
+
+
+void ScDataTableFormatList::SetList( const ScDataTableFormatList& rList, const ScDocument* pNewDoc )
+{
+    DeleteAndDestroy( 0, Count());
     size_t nCount = rList.Count();
     for (size_t i=0; i<nCount; i++)
         InsertNew( new ScDataTableFormat( *rList[i], pNewDoc));
 }
 
 
-bool ScDataTableFormatList::operator==( const ScDataTableFormatList& r ) const
-{
-    size_t nCount = Count();
-    bool bEqual = ( nCount == r.Count() );
-    for (size_t i=0; i<nCount && bEqual; i++)           // entries are sorted
-        if (!(*this)[i]->Equals( *r[i]))
-            bEqual = FALSE;
-
-    return bEqual;
-}
-
-
 ScDataTableFormat* ScDataTableFormatList::GetFormat( sal_uInt32 nKey )
 {
     /* TODO: binary search */

File sc/source/core/data/documen4.cxx

 	return nNewKey;
 }
 
+void ScDocument::SetDataTableFormatList( const ScDataTableFormatList& rList )
+{
+	if (!pDataTableFormatList)
+		pDataTableFormatList = new ScDataTableFormatList( rList );
+    else
+        pDataTableFormatList->SetList( rList, this );
+}
+
 const SfxPoolItem* ScDocument::GetEffItem(
 						SCCOL nCol, SCROW nRow, SCTAB nTab, USHORT nWhich ) const
 {

File sc/source/core/data/document.cxx

 
     if (bRemoved)
     {
-        ScDataTableFormatList* pDTabList = GetDataTableFormatList();
-        if (pDTabList)
-            pDTabList->InvalidateStyleSheet( pStyleSheet);
+        if (pDataTableFormatList)
+            pDataTableFormatList->InvalidateStyleSheet( pStyleSheet);
     }
 
 	if ( pStyleSheet && pStyleSheet->GetName() == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
             }
         }
 
-        const ScDataTableFormatList* pDTabList = GetDataTableFormatList();
-        if (pDTabList && pDTabList->IsStyleSheetUsed( rStyle, bGatherAllStyles))
+        if (pDataTableFormatList && pDataTableFormatList->IsStyleSheetUsed( rStyle, bGatherAllStyles))
             bIsUsed = TRUE;
 
         if ( bGatherAllStyles )

File sc/source/ui/docshell/docsh4.cxx

 							{
 								GetUndoManager()->AddUndoAction(
 										new ScUndoModifyStyle( this, SFX_STYLE_FAMILY_PAGE,
-													aOldData, aNewData ) );
+													aOldData, aNewData, NULL ) );
 							}
 
 							PageStyleModified( aNewName, FALSE );

File sc/source/ui/inc/undostyl.hxx

 
 class ScDocShell;
 class SfxStyleSheetBase;
+class ScDataTableFormatList;
 
 //----------------------------------------------------------------------------
 
 class ScUndoModifyStyle: public ScSimpleUndo
 {
 private:
-	SfxStyleFamily	eFamily;
-	ScStyleSaveData	aOldData;
-	ScStyleSaveData	aNewData;
+    SfxStyleFamily         eFamily;
+    ScStyleSaveData        aOldData;
+    ScStyleSaveData        aNewData;
+    ScDataTableFormatList *mpDTabList;
 
 	static void		DoChange( ScDocShell* pDocSh,
 								const String& rName, SfxStyleFamily eStyleFamily,
-								const ScStyleSaveData& rData );
+								const ScStyleSaveData& rData,
+                                const ScDataTableFormatList* pDTabList );
 
 public:
 					TYPEINFO();
+                    /// Takes ownership of pDTabList !
 					ScUndoModifyStyle( ScDocShell* pDocSh,
 										SfxStyleFamily eFam,
 										const ScStyleSaveData& rOld,
-										const ScStyleSaveData& rNew );
+										const ScStyleSaveData& rNew,
+                                        ScDataTableFormatList* pDTabList );
 	virtual 		~ScUndoModifyStyle();
 
 	virtual void	Undo();

File sc/source/ui/undo/undostyl.cxx

 #include "scmod.hxx"
 #include "inputhdl.hxx"
 #include "globstr.hrc"
+#include "datatablestyle.hxx"
 
 // -----------------------------------------------------------------------
 
 // -----------------------------------------------------------------------
 
 ScUndoModifyStyle::ScUndoModifyStyle( ScDocShell* pDocSh, SfxStyleFamily eFam,
-					const ScStyleSaveData& rOld, const ScStyleSaveData& rNew ) :
+					const ScStyleSaveData& rOld, const ScStyleSaveData& rNew,
+                    ScDataTableFormatList* pDTabList ) :
 	ScSimpleUndo( pDocSh ),
 	eFamily( eFam ),
 	aOldData( rOld ),
-	aNewData( rNew )
+	aNewData( rNew ),
+    mpDTabList( pDTabList )
 {
 }
 
 ScUndoModifyStyle::~ScUndoModifyStyle()
 {
+    delete mpDTabList;
 }
 
 String ScUndoModifyStyle::GetComment() const
 
 // static
 void ScUndoModifyStyle::DoChange( ScDocShell* pDocSh, const String& rName,
-									SfxStyleFamily eStyleFamily, const ScStyleSaveData& rData )
+									SfxStyleFamily eStyleFamily, const ScStyleSaveData& rData,
+                                    const ScDataTableFormatList* pDTabList )
 {
 	ScDocument* pDoc = pDocSh->GetDocument();
 	ScStyleSheetPool* pStlPool = pDoc->GetStyleSheetPool();
 
 			if ( eStyleFamily == SFX_STYLE_FAMILY_PARA )
 			{
+                if (pDTabList)
+                    pDoc->SetDataTableFormatList( *pDTabList);
 				lcl_DocStyleChanged( pDoc, pStyle, FALSE );		// cell styles: row heights
 			}
 			else
 void ScUndoModifyStyle::Undo()
 {
 	BeginUndo();
-	DoChange( pDocShell, aNewData.GetName(), eFamily, aOldData );
+	DoChange( pDocShell, aNewData.GetName(), eFamily, aOldData, mpDTabList );
 	EndUndo();
 }
 
 void ScUndoModifyStyle::Redo()
 {
 	BeginRedo();
-	DoChange( pDocShell, aOldData.GetName(), eFamily, aNewData );
+	DoChange( pDocShell, aOldData.GetName(), eFamily, aNewData, NULL );
 	EndRedo();
 }
 

File sc/source/ui/view/formatsh.cxx

 #include "scresid.hxx"
 #include "tabvwsh.hxx"
 #include "undostyl.hxx"
+#include "datatablestyle.hxx"
 
 
 #define ScFormatShell
 		BOOL bAddUndo = FALSE;			// add ScUndoModifyStyle (style modified)
 		ScStyleSaveData aOldData;		// for undo/redo
 		ScStyleSaveData aNewData;
+        ::std::auto_ptr<ScDataTableFormatList> xpDTabList;
 
 		SfxStyleFamily eFamily = SFX_STYLE_FAMILY_PARA;
 		const SfxPoolItem* pFamItem;
 					{
 						if ( pStyleSheet )
 						{
+                            if (bUndo)
+                            {
+                                const ScDataTableFormatList* pDTabList = pDoc->GetDataTableFormatList();
+                                if (pDTabList)
+                                    xpDTabList.reset( new ScDataTableFormatList( *pDTabList));
+                            }
 							pTabViewShell->RemoveStyleSheetInUse( (SfxStyleSheet*)pStyleSheet );
 							pStylePool->Remove( pStyleSheet );
 							pTabViewShell->InvalidateAttribs();
 //            pTabViewShell->GetActiveWin()->GrabFocus();
 
 		if ( bAddUndo && bUndo)
+        {
 			pDocSh->GetUndoManager()->AddUndoAction(
-						new ScUndoModifyStyle( pDocSh, eFamily, aOldData, aNewData ) );
+                        new ScUndoModifyStyle( pDocSh, eFamily, aOldData, 
+                            aNewData, xpDTabList.get() ) );
+            xpDTabList.release();
+        }
 
 		if ( bStyleToMarked )
 		{

File sc/source/ui/view/preview.cxx

                     {
                         pDocShell->GetUndoManager()->AddUndoAction(
                             new ScUndoModifyStyle( pDocShell, SFX_STYLE_FAMILY_PAGE,
-                            aOldData, aNewData ) );
+                                aOldData, aNewData, NULL ) );
                     }
 
                     if ( ValidTab( nTab ) )
                     {
                         pDocShell->GetUndoManager()->AddUndoAction(
                             new ScUndoModifyStyle( pDocShell, SFX_STYLE_FAMILY_PAGE,
-                            aOldData, aNewData ) );
+                                aOldData, aNewData, NULL ) );
                     }
 
                     if ( ValidTab( nTab ) )