[Libreoffice-commits] core.git: sw/inc sw/qa sw/source

Jakub Trzebiatowski ubap.dev at gmail.com
Tue Aug 16 07:35:35 UTC 2016


 sw/inc/doc.hxx                     |    2 ++
 sw/inc/swundo.hxx                  |    3 ++-
 sw/qa/extras/uiwriter/uiwriter.cxx |   26 +++++++++++++++++++++++++-
 sw/source/core/doc/tblafmt.cxx     |    8 ++++----
 sw/source/core/docnode/ndtbl.cxx   |   29 +++++++++++++++++++++++++++++
 sw/source/core/inc/UndoTable.hxx   |   14 ++++++++++++++
 sw/source/core/undo/undo.hrc       |    3 ++-
 sw/source/core/undo/undo.src       |    4 ++++
 sw/source/core/undo/untbl.cxx      |   26 ++++++++++++++++++++++++++
 sw/source/uibase/app/docst.cxx     |   19 +++++++++++++++++++
 10 files changed, 127 insertions(+), 7 deletions(-)

New commits:
commit 592a8657fa6bdc6ed72281d792c19ff0bff31387
Author: Jakub Trzebiatowski <ubap.dev at gmail.com>
Date:   Thu Aug 11 20:22:39 2016 +0200

    GSoC Writer Table Styles; Update by example
    
    + Added possibility to update style by example.
    + Fixed SwTableAutoFormat::GetBoxFormat
    
    Change-Id: I80d9334ceda0ef7e0984fb54731850034b44cd44
    Reviewed-on: https://gerrit.libreoffice.org/28063
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index cbc3145..f28bd22 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1263,6 +1263,8 @@ public:
     SwTableAutoFormat* MakeTableStyle(const OUString& rName, bool bBroadcast = false);
     // Delete table style named rName. If pAffectedTables is not null, it contains pointers to affected tables. Tracked by undo.
     std::unique_ptr<SwTableAutoFormat> DelTableStyle(const OUString& rName, bool bBroadcast = false, std::vector<SwTable*>* pAffectedTables = nullptr);
+    // Change (replace) a table style named rName. Tracked by undo.
+    void ChgTableStyle(const OUString& rName, const SwTableAutoFormat& rNewFormat);
 
     const SwCellStyleTable& GetCellStyles() const  { return *mpCellStyles.get(); }
           SwCellStyleTable& GetCellStyles()        { return *mpCellStyles.get(); }
diff --git a/sw/inc/swundo.hxx b/sw/inc/swundo.hxx
index 9a90d4a..e33ee7b 100644
--- a/sw/inc/swundo.hxx
+++ b/sw/inc/swundo.hxx
@@ -152,7 +152,8 @@ enum SwUndoId
     UNDO_FLYFRMFMT_DESCRIPTION,     // 113
     UNDO_TBLSTYLE_CREATE,           // 114
     UNDO_TBLSTYLE_DELETE,           // 115
-    UNDO_STD_END= UNDO_TBLSTYLE_DELETE,
+    UNDO_TBLSTYLE_UPDATE,           // 116
+    UNDO_STD_END= UNDO_TBLSTYLE_UPDATE,
 
     // UI undo ID's...
     UNDO_UI_REPLACE             =  UNDO_STD_END + 1,
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 813f548..a835533 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -3796,8 +3796,32 @@ void SwUiWriterTest::testTableStyleUndo()
     // check if attributes are preserved
     CPPUNIT_ASSERT(pStyle);
     CPPUNIT_ASSERT(pStyle->GetBoxFormat(0).GetBackground() == aBackground);
-    rUndoManager.Undo();
+    rUndoManager.Redo();
     CPPUNIT_ASSERT_EQUAL(sal_Int32(pDoc->GetTableStyles().size()), nStyleCount);
+
+    // undo delete so we can replace the style
+    rUndoManager.Undo();
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(pDoc->GetTableStyles().size()), nStyleCount +1 );
+    pStyle = pDoc->GetTableStyles().FindAutoFormat("Test Style");
+    CPPUNIT_ASSERT(pStyle);
+    CPPUNIT_ASSERT(pStyle->GetBoxFormat(0).GetBackground() == aBackground);
+
+    SwTableAutoFormat aNewStyle("Test Style2");
+    SvxBrushItem aBackground2(Color(0x00FF00), RES_BACKGROUND);
+    aNewStyle.GetBoxFormat(0).SetBackground(aBackground2);
+
+    pDoc->ChgTableStyle("Test Style", aNewStyle);
+    pStyle = pDoc->GetTableStyles().FindAutoFormat("Test Style");
+    CPPUNIT_ASSERT(pStyle);
+    CPPUNIT_ASSERT(pStyle->GetBoxFormat(0).GetBackground() == aBackground2);
+    rUndoManager.Undo();
+    pStyle = pDoc->GetTableStyles().FindAutoFormat("Test Style");
+    CPPUNIT_ASSERT(pStyle);
+    CPPUNIT_ASSERT(pStyle->GetBoxFormat(0).GetBackground() == aBackground);
+    rUndoManager.Redo();
+    pStyle = pDoc->GetTableStyles().FindAutoFormat("Test Style");
+    CPPUNIT_ASSERT(pStyle);
+    CPPUNIT_ASSERT(pStyle->GetBoxFormat(0).GetBackground() == aBackground2);
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index 3d46102..45937fd 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -702,15 +702,15 @@ SwBoxAutoFormat& SwTableAutoFormat::GetBoxFormat( sal_uInt8 nPos )
 {
     SAL_WARN_IF(!(nPos < 16), "sw.core", "GetBoxFormat wrong area");
 
-    SwBoxAutoFormat* pFormat = aBoxAutoFormat[ nPos ];
-    if( !pFormat )
+    SwBoxAutoFormat** pFormat = &aBoxAutoFormat[ nPos ];
+    if( !*pFormat )
     {
         // If default doesn't exist yet:
         if( !pDfltBoxAutoFormat )
             pDfltBoxAutoFormat = new SwBoxAutoFormat();
-        pFormat = pDfltBoxAutoFormat;
+        *pFormat = new SwBoxAutoFormat(*pDfltBoxAutoFormat);
     }
-    return *pFormat;
+    return **pFormat;
 }
 
 const SwBoxAutoFormat& SwTableAutoFormat::GetDefaultBoxFormat()
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index c9c9511..9bff35a 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -4671,4 +4671,33 @@ std::unique_ptr<SwTableAutoFormat> SwDoc::DelTableStyle(const OUString& rName, b
     return pReleasedFormat;
 }
 
+void SwDoc::ChgTableStyle(const OUString& rName, const SwTableAutoFormat& rNewFormat)
+{
+    SwTableAutoFormat* pFormat = GetTableStyles().FindAutoFormat(rName);
+    if (pFormat)
+    {
+        SwTableAutoFormat aOldFormat = *pFormat;
+        *pFormat = rNewFormat;
+        pFormat->SetName(rName);
+
+        size_t nTableCount = GetTableFrameFormatCount(true);
+        for (size_t i=0; i < nTableCount; ++i)
+        {
+            SwFrameFormat* pFrameFormat = &GetTableFrameFormat(i, true);
+            SwTable* pTable = SwTable::FindTable(pFrameFormat);
+            if (pTable->GetTableStyleName() == rName)
+                GetDocShell()->GetFEShell()->UpdateTableStyleFormatting(pTable->GetTableNode());
+        }
+
+        getIDocumentState().SetModified();
+
+        if (GetIDocumentUndoRedo().DoesUndo())
+        {
+            SwUndo * pUndo = new SwUndoTableStyleUpdate(rName, aOldFormat, this);
+
+            GetIDocumentUndoRedo().AppendUndo(pUndo);
+        }
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/UndoTable.hxx b/sw/source/core/inc/UndoTable.hxx
index d7bacd3..e0ad124 100644
--- a/sw/source/core/inc/UndoTable.hxx
+++ b/sw/source/core/inc/UndoTable.hxx
@@ -408,6 +408,20 @@ public:
     virtual SwRewriter GetRewriter() const override;
 };
 
+class SwUndoTableStyleUpdate : public SwUndo
+{
+    std::unique_ptr<SwTableAutoFormat> m_pOldFormat, m_pNewFormat;
+public:
+    SwUndoTableStyleUpdate(const OUString& rName, const SwTableAutoFormat& rOldFormat, const SwDoc* pDoc);
+
+    virtual ~SwUndoTableStyleUpdate();
+
+    virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
+    virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
+
+    virtual SwRewriter GetRewriter() const override;
+};
+
 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOTABLE_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/undo/undo.hrc b/sw/source/core/undo/undo.hrc
index 7ed5cdf..7e134d3 100644
--- a/sw/source/core/undo/undo.hrc
+++ b/sw/source/core/undo/undo.hrc
@@ -140,9 +140,10 @@
 #define STR_UNDO_FLYFRMFMT_DESCRITPTION         (CORE_REPEAT_END      +68)
 #define STR_UNDO_TBLSTYLE_CREATE                (CORE_REPEAT_END      +69)
 #define STR_UNDO_TBLSTYLE_DELETE                (CORE_REPEAT_END      +70)
+#define STR_UNDO_TBLSTYLE_UPDATE                (CORE_REPEAT_END      +71)
 
 // !!!!!! umsetzen !!!!!!!!!!! umsetzen !!!!!!!!!!! umsetzen !!!!
-#define CORE_UNDO_END           STR_UNDO_TBLSTYLE_DELETE// !!!! umsetzen !!!
+#define CORE_UNDO_END           STR_UNDO_TBLSTYLE_UPDATE// !!!! umsetzen !!!
 
 // UI-Undo Klammerungen
 #define UI_UNDO_BEGIN                   (CORE_UNDO_END + 1)
diff --git a/sw/source/core/undo/undo.src b/sw/source/core/undo/undo.src
index b293b4e..c92e716 100644
--- a/sw/source/core/undo/undo.src
+++ b/sw/source/core/undo/undo.src
@@ -658,6 +658,10 @@ String STR_UNDO_TBLSTYLE_DELETE
 {
     Text[ en-US ] = "Delete table style: $1";
 };
+String STR_UNDO_TBLSTYLE_UPDATE
+{
+    Text[ en-US ] = "Update table style: $1";
+};
 String STR_UNDO_TABLE_DELETE
 {
     Text [ en-US ] = "Delete table" ;
diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx
index be0801b..f6e96d6 100644
--- a/sw/source/core/undo/untbl.cxx
+++ b/sw/source/core/undo/untbl.cxx
@@ -3233,4 +3233,30 @@ SwRewriter SwUndoTableStyleDelete::GetRewriter() const
     return aResult;
 }
 
+SwUndoTableStyleUpdate::SwUndoTableStyleUpdate(const OUString& rName, const SwTableAutoFormat& rOldFormat, const SwDoc* pDoc)
+    : SwUndo(UNDO_TBLSTYLE_UPDATE, pDoc),
+    m_pOldFormat(new SwTableAutoFormat(rOldFormat)),
+    m_pNewFormat(new SwTableAutoFormat(*pDoc->GetTableStyles().FindAutoFormat(rName)))
+{ }
+
+SwUndoTableStyleUpdate::~SwUndoTableStyleUpdate()
+{ }
+
+void SwUndoTableStyleUpdate::UndoImpl(::sw::UndoRedoContext & rContext)
+{
+    rContext.GetDoc().ChgTableStyle(m_pNewFormat->GetName(), *m_pOldFormat);
+}
+
+void SwUndoTableStyleUpdate::RedoImpl(::sw::UndoRedoContext & rContext)
+{
+    rContext.GetDoc().ChgTableStyle(m_pNewFormat->GetName(), *m_pNewFormat);
+}
+
+SwRewriter SwUndoTableStyleUpdate::GetRewriter() const
+{
+    SwRewriter aResult;
+    aResult.AddRule(UndoArg1, m_pNewFormat->GetName());
+    return aResult;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index 2842808..13558bf 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -466,6 +466,12 @@ void SwDocShell::ExecStyleSheet( SfxRequest& rReq )
                             aParam = static_cast<const SfxStringItem*>(pItem)->GetValue();
                         }
                         break;
+                        case SfxStyleFamily::Table:
+                        if(SfxItemState::SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME, false, &pItem))
+                        {
+                            aParam = static_cast<const SfxStringItem*>(pItem)->GetValue();
+                        }
+                        break;
                         default: break;
                     }
                     rReq.AppendItem(SfxStringItem(nSlot, aParam));
@@ -1124,6 +1130,19 @@ SfxStyleFamily SwDocShell::UpdateStyle(const OUString &rName, SfxStyleFamily nFa
             }
         }
         break;
+        case SfxStyleFamily::Table:
+        {
+
+            SwTableAutoFormat aFormat(rName);
+            if (pCurrWrtShell->GetTableAutoFormat(aFormat))
+            {
+                pCurrWrtShell->StartAllAction();
+                pCurrWrtShell->GetDoc()->ChgTableStyle(rName, aFormat);
+                pCurrWrtShell->EndAllAction();
+            }
+
+        }
+        break;
         default: break;
     }
     return nFamily;


More information about the Libreoffice-commits mailing list