sw/inc/doc.hxx                      |   12 ++++-
 sw/inc/fesh.hxx                     |    9 ++-
 sw/inc/swtable.hxx                  |   20 ++++++++
 sw/inc/tblafmt.hxx                  |    7 ++
 sw/source/core/doc/docnew.cxx       |    2 
 sw/source/core/doc/tblafmt.cxx      |   23 ++++++++-
 sw/source/core/doc/tblrwcl.cxx      |    9 +++
 sw/source/core/docnode/ndtbl.cxx    |   85 +++++++++++++++++++++---------------
 sw/source/core/docnode/ndtbl1.cxx   |    2 
 sw/source/core/frmedt/fetab.cxx     |   33 +++++++++++--
 sw/source/core/table/swtable.cxx    |   10 ++--
 sw/source/ui/dbui/dbinsdlg.cxx      |    2 
 sw/source/ui/table/tautofmt.cxx     |    2 
 sw/source/uibase/shells/textsh1.cxx |    4 +
 14 files changed, 169 insertions(+), 51 deletions(-)

New commits:
commit 09fc6fef2d03ca8558dd6f0eec45d61ceb282cb5
Author: Jan Holesovsky <ke...@collabora.com>
Date:   Sat Sep 26 23:54:22 2015 +0200

    sw table styles: Direct formatting takes precedence over table style.
    
    Make sure we don't reset the direct formatting with the table style when
    updating.
    
    Change-Id: I07b4a687fd0403bd80d73732a66101b967398507

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 51631a3..f338348 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1255,8 +1255,9 @@ public:
 
     void SetRowsToRepeat( SwTable &rTable, sal_uInt16 nSet );
 
-    // AutoFormat for table/table selection.
-    bool SetTableAutoFormat( const SwSelBoxes& rBoxes, const 
SwTableAutoFormat& rNew );
+    /// AutoFormat for table/table selection.
+    /// @param bResetDirect Reset direct formatting that might be applied to 
the cells.
+    bool SetTableAutoFormat(const SwSelBoxes& rBoxes, const SwTableAutoFormat& 
rNew, bool bResetDirect = false);
 
     // Query attributes.
     bool GetTableAutoFormat( const SwSelBoxes& rBoxes, SwTableAutoFormat& rGet 
);
diff --git a/sw/inc/fesh.hxx b/sw/inc/fesh.hxx
index a4829e8..47fe673 100644
--- a/sw/inc/fesh.hxx
+++ b/sw/inc/fesh.hxx
@@ -725,7 +725,8 @@ public:
 
     /// Update the direct formatting according to the current table style.
     /// @param pTableNode Table node to update.  When nullptr, current cursor 
position is used.
-    bool UpdateTableStyleFormatting(SwTableNode *pTableNode = nullptr);
+    /// @param bResetDirect Reset direct formatting that might be applied to 
the cells.
+    bool UpdateTableStyleFormatting(SwTableNode *pTableNode = nullptr, bool 
bResetDirect = false);
 
     bool GetTableAutoFormat( SwTableAutoFormat& rGet );
 
diff --git a/sw/inc/swtable.hxx b/sw/inc/swtable.hxx
index 5f645e3..14e31c8 100644
--- a/sw/inc/swtable.hxx
+++ b/sw/inc/swtable.hxx
@@ -397,6 +397,9 @@ class SW_DLLPUBLIC SwTableBox: public SwClient      
//Client of FrameFormat.
     SwTableLine *pUpper;
     SwTableBox_Impl* pImpl;
 
+    /// Do we contain any direct formatting?
+    bool mbDirectFormatting;
+
     // In case Format contains formulas/values already,
     // a new one must be created for the new box.
     static SwTableBoxFormat* CheckBoxFormat( SwTableBoxFormat* );
@@ -404,7 +407,7 @@ class SW_DLLPUBLIC SwTableBox: public SwClient      
//Client of FrameFormat.
 public:
     TYPEINFO_OVERRIDE();
 
-    SwTableBox() : pSttNd(0), pUpper(0), pImpl(0) {}
+    SwTableBox() : pSttNd(0), pUpper(0), pImpl(0), mbDirectFormatting(false) {}
 
     SwTableBox( SwTableBoxFormat*, sal_uInt16 nLines, SwTableLine *pUp = 0 );
     SwTableBox( SwTableBoxFormat*, const SwStartNode&, SwTableLine *pUp = 0 );
@@ -421,6 +424,12 @@ public:
     SwFrameFormat* GetFrameFormat()       { return 
static_cast<SwFrameFormat*>(GetRegisteredIn()); }
     SwFrameFormat* GetFrameFormat() const { return 
const_cast<SwFrameFormat*>(static_cast<const 
SwFrameFormat*>(GetRegisteredIn())); }
 
+    /// Set that this table box contains formatting that is not set by the 
table style.
+    void SetDirectFormatting(bool bDirect) { mbDirectFormatting = bDirect; }
+
+    /// Do we contain any direct formatting (ie. something not affected by the 
table style)?
+    bool HasDirectFormatting() const { return mbDirectFormatting; }
+
     // Creates its own FrameFormat if more boxes depend on it.
     SwFrameFormat* ClaimFrameFormat();
     void ChgFrameFormat( SwTableBoxFormat *pNewFormat );
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 5d3499b..3911d84 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -3669,19 +3669,19 @@ struct _SetAFormatTabPara
 };
 
 // Forward declare so that the Lines and Boxes can use recursion
-static bool lcl_SetAFormatBox(_FndBox &, _SetAFormatTabPara *pSetPara);
-static bool lcl_SetAFormatLine(_FndLine &, _SetAFormatTabPara *pPara);
+static bool lcl_SetAFormatBox(_FndBox &, _SetAFormatTabPara *pSetPara, bool 
bResetDirect);
+static bool lcl_SetAFormatLine(_FndLine &, _SetAFormatTabPara *pPara, bool 
bResetDirect);
 
-static bool lcl_SetAFormatLine(_FndLine & rLine, _SetAFormatTabPara *pPara)
+static bool lcl_SetAFormatLine(_FndLine & rLine, _SetAFormatTabPara *pPara, 
bool bResetDirect)
 {
     for (auto const& it : rLine.GetBoxes())
     {
-        lcl_SetAFormatBox(*it, pPara);
+        lcl_SetAFormatBox(*it, pPara, bResetDirect);
     }
     return true;
 }
 
-static bool lcl_SetAFormatBox( _FndBox & rBox, _SetAFormatTabPara *pSetPara )
+static bool lcl_SetAFormatBox(_FndBox & rBox, _SetAFormatTabPara *pSetPara, 
bool bResetDirect)
 {
     if (!rBox.GetUpper()->GetUpper()) // Box on first level?
     {
@@ -3696,41 +3696,44 @@ static bool lcl_SetAFormatBox( _FndBox & rBox, 
_SetAFormatTabPara *pSetPara )
     if (rBox.GetBox()->GetSttNd())
     {
         SwTableBox* pSetBox = static_cast<SwTableBox*>(rBox.GetBox());
-        SwDoc* pDoc = pSetBox->GetFrameFormat()->GetDoc();
-        SfxItemSet aCharSet( pDoc->GetAttrPool(), RES_CHRATR_BEGIN, 
RES_PARATR_LIST_END-1 );
-        SfxItemSet aBoxSet( pDoc->GetAttrPool(), aTableBoxSetRange );
-        sal_uInt8 nPos = pSetPara->nAFormatLine * 4 + pSetPara->nAFormatBox;
-        pSetPara->rTableFormat.UpdateToSet( nPos, aCharSet,
-                                        SwTableAutoFormat::UPDATE_CHAR, 0 );
-        pSetPara->rTableFormat.UpdateToSet( nPos, aBoxSet,
-                                        SwTableAutoFormat::UPDATE_BOX,
-                                        pDoc->GetNumberFormatter() );
-        if( aCharSet.Count() )
+        if (!pSetBox->HasDirectFormatting() || bResetDirect)
         {
-            sal_uLong nSttNd = pSetBox->GetSttIdx()+1;
-            sal_uLong nEndNd = pSetBox->GetSttNd()->EndOfSectionIndex();
-            for( ; nSttNd < nEndNd; ++nSttNd )
+            if (bResetDirect)
+                pSetBox->SetDirectFormatting(false);
+
+            SwDoc* pDoc = pSetBox->GetFrameFormat()->GetDoc();
+            SfxItemSet aCharSet(pDoc->GetAttrPool(), RES_CHRATR_BEGIN, 
RES_PARATR_LIST_END-1);
+            SfxItemSet aBoxSet(pDoc->GetAttrPool(), aTableBoxSetRange);
+            sal_uInt8 nPos = pSetPara->nAFormatLine * 4 + 
pSetPara->nAFormatBox;
+            pSetPara->rTableFormat.UpdateToSet(nPos, aCharSet, 
SwTableAutoFormat::UPDATE_CHAR, 0);
+            pSetPara->rTableFormat.UpdateToSet(nPos, aBoxSet, 
SwTableAutoFormat::UPDATE_BOX, pDoc->GetNumberFormatter());
+
+            if (aCharSet.Count())
             {
-                SwContentNode* pNd = pDoc->GetNodes()[ nSttNd 
]->GetContentNode();
-                if( pNd )
-                    pNd->SetAttr( aCharSet );
+                sal_uLong nSttNd = pSetBox->GetSttIdx()+1;
+                sal_uLong nEndNd = pSetBox->GetSttNd()->EndOfSectionIndex();
+                for (; nSttNd < nEndNd; ++nSttNd)
+                {
+                    SwContentNode* pNd = pDoc->GetNodes()[ nSttNd 
]->GetContentNode();
+                    if (pNd)
+                        pNd->SetAttr(aCharSet);
+                }
             }
-        }
 
-        if( aBoxSet.Count() )
-        {
-            if( pSetPara->pUndo &&
-                SfxItemState::SET == aBoxSet.GetItemState( RES_BOXATR_FORMAT ))
-                pSetPara->pUndo->SaveBoxContent( *pSetBox );
+            if (aBoxSet.Count())
+            {
+                if (pSetPara->pUndo && SfxItemState::SET == 
aBoxSet.GetItemState(RES_BOXATR_FORMAT))
+                    pSetPara->pUndo->SaveBoxContent( *pSetBox );
 
-            pSetBox->ClaimFrameFormat()->SetFormatAttr( aBoxSet );
+                pSetBox->ClaimFrameFormat()->SetFormatAttr(aBoxSet);
+            }
         }
     }
     else
     {
         for (auto const& rpFndLine : rBox.GetLines())
         {
-            lcl_SetAFormatLine( *rpFndLine, pSetPara );
+            lcl_SetAFormatLine(*rpFndLine, pSetPara, bResetDirect);
         }
     }
 
@@ -3739,10 +3742,7 @@ static bool lcl_SetAFormatBox( _FndBox & rBox, 
_SetAFormatTabPara *pSetPara )
     return true;
 }
 
-/**
- * AutoFormat for the Table/TableSelection
- */
-bool SwDoc::SetTableAutoFormat( const SwSelBoxes& rBoxes, const 
SwTableAutoFormat& rNew )
+bool SwDoc::SetTableAutoFormat(const SwSelBoxes& rBoxes, const 
SwTableAutoFormat& rNew, bool bResetDirect)
 {
     OSL_ENSURE( !rBoxes.empty(), "No valid Box list" );
     SwTableNode* pTableNd = 
const_cast<SwTableNode*>(rBoxes[0]->GetSttNd()->FindTableNode());
@@ -3807,7 +3807,7 @@ bool SwDoc::SetTableAutoFormat( const SwSelBoxes& rBoxes, 
const SwTableAutoForma
         aPara.pUndo = pUndo;
         for (auto const& it : pLine->GetBoxes())
         {
-            lcl_SetAFormatBox(*it, &aPara);
+            lcl_SetAFormatBox(*it, &aPara, bResetDirect);
         }
 
         pLine->SetUpper( pSaveBox );
diff --git a/sw/source/core/docnode/ndtbl1.cxx 
b/sw/source/core/docnode/ndtbl1.cxx
index 797c159..8a4d953 100644
--- a/sw/source/core/docnode/ndtbl1.cxx
+++ b/sw/source/core/docnode/ndtbl1.cxx
@@ -1155,6 +1155,8 @@ void SwDoc::SetBoxAttr( const SwCursor& rCursor, const 
SfxPoolItem &rNew )
                 pNew->SetFormatAttr( rNew );
                 aFormatCmp.push_back( new SwTableFormatCmp( pOld, pNew, 0 ) );
             }
+
+            pBox->SetDirectFormatting(true);
         }
 
         SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx
index 5d4551c..f996e1e 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -1190,7 +1190,7 @@ bool SwFEShell::SetTableStyle(const SwTableAutoFormat& 
rStyle)
     return UpdateTableStyleFormatting(pTableNode);
 }
 
-bool SwFEShell::UpdateTableStyleFormatting(SwTableNode *pTableNode)
+bool SwFEShell::UpdateTableStyleFormatting(SwTableNode *pTableNode, bool 
bResetDirect)
 {
     if (!pTableNode)
     {
@@ -1227,7 +1227,7 @@ bool SwFEShell::UpdateTableStyleFormatting(SwTableNode 
*pTableNode)
     {
         SET_CURR_SHELL( this );
         StartAllAction();
-        bRet = GetDoc()->SetTableAutoFormat(aBoxes, *pTableStyle);
+        bRet = GetDoc()->SetTableAutoFormat(aBoxes, *pTableStyle, 
bResetDirect);
         DELETEZ( pLastCols );
         DELETEZ( pLastRows );
         EndAllActionAndCall();
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index 3a6abf1..a3dfb89f 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -1650,7 +1650,8 @@ SwTableBox::SwTableBox( SwTableBoxFormat* pFormat, 
sal_uInt16 nLines, SwTableLin
     aLines(),
     pSttNd( 0 ),
     pUpper( pUp ),
-    pImpl( 0 )
+    pImpl( 0 ),
+    mbDirectFormatting(false)
 {
     aLines.reserve( nLines );
     CheckBoxFormat( pFormat )->Add( this );
@@ -1661,7 +1662,8 @@ SwTableBox::SwTableBox( SwTableBoxFormat* pFormat, const 
SwNodeIndex &rIdx,
     : SwClient( 0 ),
     aLines(),
     pUpper( pUp ),
-    pImpl( 0 )
+    pImpl( 0 ),
+    mbDirectFormatting(false)
 {
     CheckBoxFormat( pFormat )->Add( this );
 
@@ -1681,7 +1683,8 @@ SwTableBox::SwTableBox( SwTableBoxFormat* pFormat, const 
SwStartNode& rSttNd, Sw
     aLines(),
     pSttNd( &rSttNd ),
     pUpper( pUp ),
-    pImpl( 0 )
+    pImpl( 0 ),
+    mbDirectFormatting(false)
 {
     CheckBoxFormat( pFormat )->Add( this );
 
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index 49a1dc5..3aef579 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -540,6 +540,10 @@ void SwTextShell::Execute(SfxRequest &rReq)
             // we don't want to change writing direction.
             aAttribs.erase( RES_FRAMEDIR );
             rWrtSh.ResetAttr( aAttribs );
+
+            // also clear the direct formatting flag inside SwTableBox(es)
+            
GetView().GetDocShell()->GetFEShell()->UpdateTableStyleFormatting(nullptr, 
true);
+
             rReq.Done();
             break;
         }
commit 73f4a06c0bce51c7c8b9ae9adfdc7ffac27d06b4
Author: Jan Holesovsky <ke...@collabora.com>
Date:   Sat Sep 26 17:55:31 2015 +0200

    sw table styles: Insert column, split table, delete row/column.
    
    Make these operations applying the table style too.
    
    Change-Id: Iee2808a5a5c5f84538474b8fbc6bf53d1fab19b7

diff --git a/sw/inc/fesh.hxx b/sw/inc/fesh.hxx
index a41e119..a4829e8 100644
--- a/sw/inc/fesh.hxx
+++ b/sw/inc/fesh.hxx
@@ -724,7 +724,8 @@ public:
     bool SetTableStyle(const SwTableAutoFormat& rNew);
 
     /// Update the direct formatting according to the current table style.
-    bool UpdateTableStyleFormatting();
+    /// @param pTableNode Table node to update.  When nullptr, current cursor 
position is used.
+    bool UpdateTableStyleFormatting(SwTableNode *pTableNode = nullptr);
 
     bool GetTableAutoFormat( SwTableAutoFormat& rGet );
 
diff --git a/sw/source/core/doc/tblrwcl.cxx b/sw/source/core/doc/tblrwcl.cxx
index 9574e0a..acc2d8e 100644
--- a/sw/source/core/doc/tblrwcl.cxx
+++ b/sw/source/core/doc/tblrwcl.cxx
@@ -550,6 +550,8 @@ bool SwTable::InsertCol( SwDoc* pDoc, const SwSelBoxes& 
rBoxes, sal_uInt16 nCnt,
         pPCD->AddRowCols( *this, rBoxes, nCnt, bBehind );
     pDoc->UpdateCharts( GetFrameFormat()->GetName() );
 
+    pDoc->GetDocShell()->GetFEShell()->UpdateTableStyleFormatting();
+
     return bRes;
 }
 
@@ -2095,6 +2097,8 @@ bool SwTable::MakeCopy( SwDoc* pInsDoc, const SwPosition& 
rPos,
 
     pTableNd->GetTable().SetRowsToRepeat( GetRowsToRepeat() );
 
+    pNewTable->SetTableStyleName(pTableNd->GetTable().GetTableStyleName());
+
     if( IS_TYPE( SwDDETable, this ))
     {
         // A DDE-Table is being copied
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 5f50cc9..5d3499b 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -2104,8 +2104,12 @@ bool SwDoc::DeleteRowCol( const SwSelBoxes& rBoxes, bool 
bColumn )
             pTableNd->DelFrms();
             getIDocumentContentOperations().DeleteSection( pTableNd );
         }
+
+        GetDocShell()->GetFEShell()->UpdateTableStyleFormatting();
+
         getIDocumentState().SetModified();
         getIDocumentFieldsAccess().SetFieldsDirty( true, NULL, 0 );
+
         return true;
     }
 
@@ -2135,6 +2139,8 @@ bool SwDoc::DeleteRowCol( const SwSelBoxes& rBoxes, bool 
bColumn )
         bRet = rTable.DeleteSel( this, aSelBoxes, 0, pUndo, true, true );
         if (bRet)
         {
+            GetDocShell()->GetFEShell()->UpdateTableStyleFormatting();
+
             getIDocumentState().SetModified();
             getIDocumentFieldsAccess().SetFieldsDirty( true, NULL, 0 );
         }
@@ -2203,6 +2209,8 @@ bool SwDoc::SplitTable( const SwSelBoxes& rBoxes, bool 
bVert, sal_uInt16 nCnt,
 
         if (bRet)
         {
+            GetDocShell()->GetFEShell()->UpdateTableStyleFormatting();
+
             getIDocumentState().SetModified();
             getIDocumentFieldsAccess().SetFieldsDirty( true, NULL, 0 );
         }
@@ -2310,6 +2318,7 @@ sal_uInt16 SwDoc::MergeTable( SwPaM& rPam )
         if( pTableNd->GetTable().Merge( this, aBoxes, aMerged, pMergeBox, 
pUndo ))
         {
             nRet = TBLMERGE_OK;
+
             getIDocumentState().SetModified();
             getIDocumentFieldsAccess().SetFieldsDirty( true, NULL, 0 );
             if( pUndo )
@@ -3257,6 +3266,10 @@ bool SwDoc::SplitTable( const SwPosition& rPos, 
sal_uInt16 eHdlnMode,
     // TL_CHART2: need to inform chart of probably changed cell names
     UpdateCharts( rTable.GetFrameFormat()->GetName() );
 
+    // update table style formatting of both the tables
+    GetDocShell()->GetFEShell()->UpdateTableStyleFormatting(pTNd);
+    GetDocShell()->GetFEShell()->UpdateTableStyleFormatting(pNew);
+
     getIDocumentFieldsAccess().SetFieldsDirty( true, NULL, 0 );
 
     return 0 != pNew;
@@ -3457,6 +3470,8 @@ SwTableNode* SwNodes::SplitTable( const SwNodeIndex& 
rPos, bool bAfter,
         *pNewTableFormat = *pOldTableFormat;
         pNewTableNd->GetTable().RegisterToFormat( *pNewTableFormat );
 
+        pNewTableNd->GetTable().SetTableStyleName(rTable.GetTableStyleName());
+
         // Calculate a new Size?
         // lcl_ChgTableSize: Only execute the second call if the first call was
         // successful, thus has an absolute Size
@@ -3527,6 +3542,8 @@ bool SwDoc::MergeTable( const SwPosition& rPos, bool 
bWithPrev, sal_uInt16 nMode
     }
     if( bRet )
     {
+        GetDocShell()->GetFEShell()->UpdateTableStyleFormatting();
+
         getIDocumentState().SetModified();
         getIDocumentFieldsAccess().SetFieldsDirty( true, NULL, 0 );
     }
diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx
index 191ba23..5d4551c 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -1181,22 +1181,25 @@ bool SwFEShell::SetTableStyle(const SwTableAutoFormat& 
rStyle)
     // make sure SwDoc has the style
     GetDoc()->GetTableStyles().AddAutoFormat(rStyle);
 
-    SwTableNode *pTableNd = const_cast<SwTableNode*>(IsCrsrInTable());
-    if (!pTableNd)
+    SwTableNode *pTableNode = const_cast<SwTableNode*>(IsCrsrInTable());
+    if (!pTableNode)
         return false;
 
     // set the name & update
-    pTableNd->GetTable().SetTableStyleName(rStyle.GetName());
-    return UpdateTableStyleFormatting();
+    pTableNode->GetTable().SetTableStyleName(rStyle.GetName());
+    return UpdateTableStyleFormatting(pTableNode);
 }
 
-bool SwFEShell::UpdateTableStyleFormatting()
+bool SwFEShell::UpdateTableStyleFormatting(SwTableNode *pTableNode)
 {
-    SwTableNode *pTableNd = const_cast<SwTableNode*>(IsCrsrInTable());
-    if( !pTableNd || pTableNd->GetTable().IsTableComplex() )
-        return false;
+    if (!pTableNode)
+    {
+        pTableNode = const_cast<SwTableNode*>(IsCrsrInTable());
+        if (!pTableNode || pTableNode->GetTable().IsTableComplex())
+            return false;
+    }
 
-    OUString aTableStyleName(pTableNd->GetTable().GetTableStyleName());
+    OUString aTableStyleName(pTableNode->GetTable().GetTableStyleName());
     SwTableAutoFormat* pTableStyle = 
GetDoc()->GetTableStyles().FindAutoFormat(aTableStyleName);
     if (!pTableStyle)
         return false;
@@ -1211,7 +1214,7 @@ bool SwFEShell::UpdateTableStyleFormatting()
         ::GetTableSelCrs( *this, aBoxes );
     else
     {
-        const SwTableSortBoxes& rTBoxes = 
pTableNd->GetTable().GetTabSortBoxes();
+        const SwTableSortBoxes& rTBoxes = 
pTableNode->GetTable().GetTabSortBoxes();
         for (size_t n = 0; n < rTBoxes.size(); ++n)
         {
             SwTableBox* pBox = rTBoxes[ n ];
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index ca75280..3a6abf1 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -264,6 +264,7 @@ SwTable::SwTable( const SwTable& rTable )
     eTableChgMode( rTable.eTableChgMode ),
     nGrfsThatResize( 0 ),
     nRowsToRepeat( rTable.GetRowsToRepeat() ),
+    maTableStyleName(rTable.maTableStyleName),
     bModifyLocked( false ),
     bNewModel( rTable.bNewModel )
 {
commit ac6f8bc92b1abe995694602f43d8ad108b7030fb
Author: Jan Holesovsky <ke...@collabora.com>
Date:   Sat Sep 26 16:19:24 2015 +0200

    sw table styles: Implement table styles in Writer.
    
    This extends the table auto formats so that SwDoc keeps track of the auto
    formats used in the document.  With this in mind, we can update the format 
of
    the table with every operation like adding/removing a line, splitting a 
table,
    etc.
    
    So far we only have the core functionality, and cover inserting a line in
    the table; more to come.
    
    Based on work of Alex Ivan <alexni...@yahoo.com> during GSoC 2013 - thank 
you!
    
    Change-Id: I7839147e54c2f976988121a523331def9859f4c2

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 2ddcc2d..51631a3 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -127,6 +127,7 @@ class SwSectionFormat;
 class SwSectionFormats;
 class SwSectionData;
 class SwSelBoxes;
+class SwTableAutoFormatTable;
 class SwTOXBaseSection;
 class SwTOXTypes;
 class SwTabCols;
@@ -343,6 +344,9 @@ class SW_DLLPUBLIC SwDoc :
     com::sun::star::uno::Reference< 
com::sun::star::script::vba::XVBAEventProcessor > mxVbaEvents;
     com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> 
m_xTemplateToProjectCache;
 
+    /// Table styles (autoformats that are applied with table changes).
+    std::unique_ptr<SwTableAutoFormatTable> mpTableStyles;
+
 private:
     ::std::unique_ptr< ::sfx2::IXmlIdRegistry > m_pXmlIdRegistry;
 
@@ -1257,6 +1261,9 @@ public:
     // Query attributes.
     bool GetTableAutoFormat( const SwSelBoxes& rBoxes, SwTableAutoFormat& rGet 
);
 
+    /// Return the available table styles.
+    SwTableAutoFormatTable& GetTableStyles() { return *mpTableStyles.get(); }
+
     void AppendUndoForInsertFromDB( const SwPaM& rPam, bool bIsTable );
 
     bool SetColRowWidthHeight( SwTableBox& rAktBox, sal_uInt16 eType,
diff --git a/sw/inc/fesh.hxx b/sw/inc/fesh.hxx
index a219ac1..a41e119 100644
--- a/sw/inc/fesh.hxx
+++ b/sw/inc/fesh.hxx
@@ -720,8 +720,11 @@ public:
     /// Not allowed if only empty cells are selected.
     bool IsAdjustCellWidthAllowed( bool bBalance = false ) const;
 
-    /// AutoFormat for table/ table selection.
-    bool SetTableAutoFormat( const SwTableAutoFormat& rNew );
+    /// Set table style of the current table.
+    bool SetTableStyle(const SwTableAutoFormat& rNew);
+
+    /// Update the direct formatting according to the current table style.
+    bool UpdateTableStyleFormatting();
 
     bool GetTableAutoFormat( SwTableAutoFormat& rGet );
 
diff --git a/sw/inc/swtable.hxx b/sw/inc/swtable.hxx
index 8b42d9d..5f645e3 100644
--- a/sw/inc/swtable.hxx
+++ b/sw/inc/swtable.hxx
@@ -114,6 +114,9 @@ protected:
                                         // at HTML-import.
     sal_uInt16      nRowsToRepeat;      // Number of rows to repeat on every 
page.
 
+    /// Name of the table style to be applied on this table.
+    OUString maTableStyleName;
+
     bool        bModifyLocked   :1;
     bool        bNewModel       :1; // false: old SubTableModel; true: new 
RowSpanModel
 #ifdef DBG_UTIL
@@ -175,6 +178,12 @@ public:
     void SetTableModel( bool bNew ){ bNewModel = bNew; }
     bool IsNewModel() const { return bNewModel; }
 
+    /// Return the table style name of this table.
+    OUString GetTableStyleName() const { return maTableStyleName; }
+
+    /// Set the new table style name for this table.
+    void SetTableStyleName(const OUString& rName) { maTableStyleName = rName; }
+
     sal_uInt16 GetRowsToRepeat() const { return std::min( 
(sal_uInt16)GetTabLines().size(), nRowsToRepeat ); }
     sal_uInt16 _GetRowsToRepeat() const { return nRowsToRepeat; }
     void SetRowsToRepeat( sal_uInt16 nNumOfRows ) { nRowsToRepeat = 
nNumOfRows; }
diff --git a/sw/inc/tblafmt.hxx b/sw/inc/tblafmt.hxx
index 3503bb7..500e2ca 100644
--- a/sw/inc/tblafmt.hxx
+++ b/sw/inc/tblafmt.hxx
@@ -310,10 +310,17 @@ public:
     size_t size() const;
     SwTableAutoFormat const& operator[](size_t i) const;
     SwTableAutoFormat      & operator[](size_t i);
+
+    /// Append table style to the existing styles.
+    void AddAutoFormat(const SwTableAutoFormat& rFormat);
+
     void InsertAutoFormat(size_t i, std::unique_ptr<SwTableAutoFormat> 
pFormat);
     void EraseAutoFormat(size_t i);
     std::unique_ptr<SwTableAutoFormat> ReleaseAutoFormat(size_t i);
 
+    /// Find table style with the provided name, return nullptr when not found.
+    SwTableAutoFormat* FindAutoFormat(const OUString& rName) const;
+
     bool Load();
     bool Save() const;
 };
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index d65ef4a..74ab1f1 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -84,6 +84,7 @@
 #include <istyleaccess.hxx>
 #include <swstylemanager.hxx>
 #include <IGrammarContact.hxx>
+#include <tblafmt.hxx>
 #include <tblsel.hxx>
 #include <MarkManager.hxx>
 #include <UndoManager.hxx>
@@ -255,6 +256,7 @@ SwDoc::SwDoc()
     mpStyleAccess( 0 ),
     mpLayoutCache( 0 ),
     mpGrammarContact(createGrammarContact()),
+    mpTableStyles(new SwTableAutoFormatTable),
     m_pXmlIdRegistry(),
     mReferenceCount(0),
     mbGlossDoc(false),
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index 6d2f4e5..2b5cf7d 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -1025,8 +1025,16 @@ SwTableAutoFormat      & 
SwTableAutoFormatTable::operator[](size_t const i)
     return *m_pImpl->m_AutoFormats[i];
 }
 
-void
-SwTableAutoFormatTable::InsertAutoFormat(size_t const i, 
std::unique_ptr<SwTableAutoFormat> pFormat)
+void SwTableAutoFormatTable::AddAutoFormat(const SwTableAutoFormat& 
rTableStyle)
+{
+    // don't insert when we already have style of this name
+    if (FindAutoFormat(rTableStyle.GetName()))
+        return;
+
+    InsertAutoFormat(size(), std::unique_ptr<SwTableAutoFormat>(new 
SwTableAutoFormat(rTableStyle)));
+}
+
+void SwTableAutoFormatTable::InsertAutoFormat(size_t const i, 
std::unique_ptr<SwTableAutoFormat> pFormat)
 {
     m_pImpl->m_AutoFormats.insert(m_pImpl->m_AutoFormats.begin() + i, 
std::move(pFormat));
 }
@@ -1044,6 +1052,17 @@ std::unique_ptr<SwTableAutoFormat> 
SwTableAutoFormatTable::ReleaseAutoFormat(siz
     return pRet;
 }
 
+SwTableAutoFormat* SwTableAutoFormatTable::FindAutoFormat(const OUString& 
rName) const
+{
+    for (auto &rFormat : m_pImpl->m_AutoFormats)
+    {
+        if (rFormat->GetName() == rName)
+            return rFormat.get();
+    }
+
+    return nullptr;
+}
+
 SwTableAutoFormatTable::~SwTableAutoFormatTable()
 {
 }
diff --git a/sw/source/core/doc/tblrwcl.cxx b/sw/source/core/doc/tblrwcl.cxx
index d96864d..9574e0a 100644
--- a/sw/source/core/doc/tblrwcl.cxx
+++ b/sw/source/core/doc/tblrwcl.cxx
@@ -36,11 +36,14 @@
 #include <IDocumentStylePoolAccess.hxx>
 #include <IDocumentFieldsAccess.hxx>
 #include <cntfrm.hxx>
+#include <docsh.hxx>
+#include <fesh.hxx>
 #include <tabfrm.hxx>
 #include <frmtool.hxx>
 #include <pam.hxx>
 #include <swtable.hxx>
 #include <ndtxt.hxx>
+#include <tblafmt.hxx>
 #include <tblsel.hxx>
 #include <fldbas.hxx>
 #include <swundo.hxx>
@@ -647,6 +650,8 @@ bool SwTable::_InsertRow( SwDoc* pDoc, const SwSelBoxes& 
rBoxes,
         pPCD->AddRowCols( *this, rBoxes, nCnt, bBehind );
     pDoc->UpdateCharts( GetFrameFormat()->GetName() );
 
+    pDoc->GetDocShell()->GetFEShell()->UpdateTableStyleFormatting();
+
     return true;
 }
 
diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx
index 4735403..191ba23 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -49,6 +49,7 @@
 #include <ndtxt.hxx>
 #include <calc.hxx>
 #include <tabcol.hxx>
+#include <tblafmt.hxx>
 #include <cellatr.hxx>
 #include <pam.hxx>
 #include <pamtyp.hxx>
@@ -1175,12 +1176,31 @@ bool SwFEShell::IsAdjustCellWidthAllowed( bool bBalance 
) const
 }
 
     // AutoFormat for the table/table selection
-bool SwFEShell::SetTableAutoFormat( const SwTableAutoFormat& rNew )
+bool SwFEShell::SetTableStyle(const SwTableAutoFormat& rStyle)
+{
+    // make sure SwDoc has the style
+    GetDoc()->GetTableStyles().AddAutoFormat(rStyle);
+
+    SwTableNode *pTableNd = const_cast<SwTableNode*>(IsCrsrInTable());
+    if (!pTableNd)
+        return false;
+
+    // set the name & update
+    pTableNd->GetTable().SetTableStyleName(rStyle.GetName());
+    return UpdateTableStyleFormatting();
+}
+
+bool SwFEShell::UpdateTableStyleFormatting()
 {
     SwTableNode *pTableNd = const_cast<SwTableNode*>(IsCrsrInTable());
     if( !pTableNd || pTableNd->GetTable().IsTableComplex() )
         return false;
 
+    OUString aTableStyleName(pTableNd->GetTable().GetTableStyleName());
+    SwTableAutoFormat* pTableStyle = 
GetDoc()->GetTableStyles().FindAutoFormat(aTableStyleName);
+    if (!pTableStyle)
+        return false;
+
     SwSelBoxes aBoxes;
 
     if ( !IsTableMode() )       // if cursors are not current
@@ -1204,7 +1224,7 @@ bool SwFEShell::SetTableAutoFormat( const 
SwTableAutoFormat& rNew )
     {
         SET_CURR_SHELL( this );
         StartAllAction();
-        bRet = GetDoc()->SetTableAutoFormat( aBoxes, rNew );
+        bRet = GetDoc()->SetTableAutoFormat(aBoxes, *pTableStyle);
         DELETEZ( pLastCols );
         DELETEZ( pLastRows );
         EndAllActionAndCall();
diff --git a/sw/source/ui/dbui/dbinsdlg.cxx b/sw/source/ui/dbui/dbinsdlg.cxx
index d84b7d0..8d2f1dc 100644
--- a/sw/source/ui/dbui/dbinsdlg.cxx
+++ b/sw/source/ui/dbui/dbinsdlg.cxx
@@ -1179,7 +1179,7 @@ void SwInsertDBColAutoPilot::DataToDoc( const 
Sequence<Any>& rSelection,
                 SetTabSet();
 
             if( pTAutoFormat )
-                rSh.SetTableAutoFormat( *pTAutoFormat );
+                rSh.SetTableStyle(*pTAutoFormat);
         }
         rSh.SetAutoUpdateCells( bIsAutoUpdateCells );
     }
diff --git a/sw/source/ui/table/tautofmt.cxx b/sw/source/ui/table/tautofmt.cxx
index 42e9042..6c127eb 100644
--- a/sw/source/ui/table/tautofmt.cxx
+++ b/sw/source/ui/table/tautofmt.cxx
@@ -498,7 +498,7 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, SelFormatHdl)
 IMPL_LINK_NOARG_TYPED(SwAutoFormatDlg, OkHdl, Button*, void)
 {
     if( bSetAutoFormat )
-        pShell->SetTableAutoFormat( (*pTableTable)[ nIndex ] );
+        pShell->SetTableStyle((*pTableTable)[nIndex]);
     EndDialog( RET_OK );
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to