[Libreoffice-commits] core.git: Branch 'feature/table-style' - 2 commits - sw/source

Alex Ivan alexnivan at yahoo.com
Mon Aug 12 11:09:05 PDT 2013


 sw/source/core/doc/swtblfmt.cxx  |    2 +-
 sw/source/core/doc/tblafmt.cxx   |    4 ++--
 sw/source/core/inc/UndoTable.hxx |    3 ++-
 sw/source/core/undo/untbl.cxx    |   38 ++++++++++++++++++++++++++++++++++----
 4 files changed, 39 insertions(+), 8 deletions(-)

New commits:
commit bef91df4dc67cb0af0f57c323f1c8339dbf5a329
Author: Alex Ivan <alexnivan at yahoo.com>
Date:   Mon Aug 12 20:59:41 2013 +0300

    Fix undo resize table causing lose of table style
    
    _SaveTable class now memorizes the name of the table style
    applied to the table and it is reapplied after undoing.
    
    Not the most elegant solution, but given how the _Save* classes
    currently store data on the table, this solution avoids modifying
    too much and possibly breaking other things.
    
    Change-Id: I5c2afb0cdd5eb447f548249e9afa1dd6d648e3a9

diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx
index 6aca5e7..9a89ab1 100644
--- a/sw/source/core/undo/untbl.cxx
+++ b/sw/source/core/undo/untbl.cxx
@@ -116,6 +116,7 @@ class _SaveTable
     SfxItemSet aTblSet;
     _SaveLine* pLine;
     const SwTable* pSwTable;
+    String sSaveFmtName;
     SfxItemSets aSets;
     SwFrmFmts aFrmFmts;
     sal_uInt16 nLineCount;
@@ -874,6 +875,11 @@ _SaveTable::_SaveTable( const SwTable& rTbl, sal_uInt16 nLnCnt, bool bSaveFml )
     bModifyBox = false;
     bNewModel = rTbl.IsNewModel();
     aTblSet.Put( rTbl.GetFrmFmt()->GetAttrSet() );
+
+    SwTableFmt* pSaveFmt = (SwTableFmt*)rTbl.GetTableFmt()->GetRegisteredIn();
+    if( pSaveFmt )
+        sSaveFmtName = pSaveFmt->GetName();
+
     pLine = new _SaveLine( 0, *rTbl.GetTabLines()[ 0 ], *this );
 
     _SaveLine* pLn = pLine;
@@ -931,6 +937,7 @@ void _SaveTable::RestoreAttr( SwTable& rTbl, bool bMdfyBox )
 
     // first, get back attributes of TableFrmFormat
     SwFrmFmt* pFmt = rTbl.GetFrmFmt();
+    SwDoc* pDoc = pFmt->GetDoc();
     SfxItemSet& rFmtSet  = (SfxItemSet&)pFmt->GetAttrSet();
     rFmtSet.ClearItem();
     rFmtSet.Put( aTblSet );
@@ -971,6 +978,14 @@ void _SaveTable::RestoreAttr( SwTable& rTbl, bool bMdfyBox )
         pLn->RestoreAttr( *rTbl.GetTabLines()[ n ], *this );
     }
 
+    if( !sSaveFmtName.Len() )
+        SwTableFmt::RestoreTableProperties( NULL, rTbl );
+    else
+    {
+        SwTableFmt* pStyle = pDoc->FindTblFmtByName( sSaveFmtName, sal_True );
+        SwTableFmt::RestoreTableProperties( pStyle, rTbl );
+    }
+
     aFrmFmts.clear();
     bModifyBox = false;
 }
commit 6538a97573635fe9d8cfa595963d7d18394a25c6
Author: Alex Ivan <alexnivan at yahoo.com>
Date:   Mon Aug 12 20:02:17 2013 +0300

    Store table style in Undo by name
    
    Undo object no longer stores a pointer to the
    style, but rather the name of the respective table style.
    
    Change-Id: I1f6f196569d33353a9075489d136df9e5075d36b

diff --git a/sw/source/core/doc/swtblfmt.cxx b/sw/source/core/doc/swtblfmt.cxx
index 276c37a..965f3e8 100644
--- a/sw/source/core/doc/swtblfmt.cxx
+++ b/sw/source/core/doc/swtblfmt.cxx
@@ -250,7 +250,7 @@ void SwTableFmt::RestoreTableProperties( SwTableFmt* pSrcFmt, SwTable &rTable )
         bRowSplit = pSrcFmt->GetRowSplit();
         nRepeatHeading = pSrcFmt->GetRepeatHeading();
     }
-    else
+    else if( pTableStyle )
         pTableStyle->Remove( pHardFmt );
 
     AssignFormatParents( pSrcFmt, rTable );
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index 8881553..976aa0a 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -846,7 +846,7 @@ SwTableAutoFmt* SwTableAutoFmt::Load( SvStream& rStream, const SwAfVersions& rVe
         // ideal, the table styles are created with the document
         SwTableFmt* pStyle = pDoc->FindTblFmtByName(aName);
         if ( !pStyle )
-            pStyle = pDoc->MakeTblFrmFmt(aName, NULL);
+            pStyle = pDoc->MakeTblFrmFmt( aName, pDoc->GetDfltFrmFmt() );
         pRet = new SwTableAutoFmt( aName, pStyle );
 
         pRet->nStrResId = nStrResId;
@@ -967,7 +967,7 @@ SwTableAutoFmtTbl::SwTableAutoFmtTbl(SwDoc* pDoc)
     sNm = SwStyleNameMapper::GetUIName( RES_POOLCOLL_STANDARD, sNm );
     SwTableFmt* pStyle = pDoc->FindTblFmtByName(sNm);
     if ( !pStyle )
-        pStyle = pDoc->MakeTblFrmFmt(sNm, NULL);
+        pStyle = pDoc->MakeTblFrmFmt( sNm, pDoc->GetDfltFrmFmt() );
     SwTableAutoFmt* pNewTableAutoFmt = new SwTableAutoFmt( sNm, pStyle );
 
     SwTableBoxFmt* pNewBoxFmt = pDoc->MakeTableBoxFmt();
diff --git a/sw/source/core/inc/UndoTable.hxx b/sw/source/core/inc/UndoTable.hxx
index 09bed01..4170c21 100644
--- a/sw/source/core/inc/UndoTable.hxx
+++ b/sw/source/core/inc/UndoTable.hxx
@@ -147,7 +147,8 @@ class SwUndoTblNumFmt;
 class SwUndoTblAutoFmt : public SwUndo
 {
     sal_uLong nSttNode;
-    SwTableFmt* pSaveFmt;
+    String sSaveFmtName;
+    //String sEmptyStr;
     sal_uInt16 m_nRepeatHeading;
 
     void UndoRedo(bool const bUndo, ::sw::UndoRedoContext & rContext);
diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx
index 5ddb001..6aca5e7 100644
--- a/sw/source/core/undo/untbl.cxx
+++ b/sw/source/core/undo/untbl.cxx
@@ -1411,7 +1411,9 @@ SwUndoTblAutoFmt::SwUndoTblAutoFmt( const SwTableNode& rTblNd )
     nSttNode( rTblNd.GetIndex() ),
     m_nRepeatHeading(rTblNd.GetTable().GetRowsToRepeat())
 {
-    pSaveFmt = (SwTableFmt*)rTblNd.GetTable().GetTableFmt()->GetRegisteredIn();
+    SwTableFmt* pSaveFmt = (SwTableFmt*)rTblNd.GetTable().GetTableFmt()->GetRegisteredIn();
+    if( pSaveFmt )
+        sSaveFmtName = pSaveFmt->GetName();
 }
 
 void
@@ -1422,13 +1424,26 @@ SwUndoTblAutoFmt::UndoRedo(bool const bUndo, ::sw::UndoRedoContext & rContext)
     OSL_ENSURE( pTblNd, "no TableNode" );
 
     SwTable& table = pTblNd->GetTable();
-    SwTableFmt* pOrig = (SwTableFmt*)table.GetTableFmt()->GetRegisteredIn();
+    String sOrigFmtName;
+    SwTableFmt* pStyle;
+    SwTableFmt* pSaveFmt = (SwTableFmt*)pTblNd->GetTable().GetTableFmt()->GetRegisteredIn();
+    if( pSaveFmt )
+        sOrigFmtName = pSaveFmt->GetName();
+    else
+        sOrigFmtName = UniString::EmptyString();
 
     if( bUndo )
         table.SetRowsToRepeat( m_nRepeatHeading );
 
-    SwTableFmt::RestoreTableProperties( pSaveFmt, table );
-    pSaveFmt = pOrig;
+    if( !sSaveFmtName.Len() )
+        SwTableFmt::RestoreTableProperties( NULL, table );
+    else
+    {
+        pStyle = rDoc.FindTblFmtByName( sSaveFmtName, sal_True );
+        SwTableFmt::RestoreTableProperties( pStyle, table );
+    }
+
+    sSaveFmtName = sOrigFmtName;
 }
 
 void SwUndoTblAutoFmt::UndoImpl(::sw::UndoRedoContext & rContext)


More information about the Libreoffice-commits mailing list