summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2015-09-26 16:19:24 +0200
committerJan Holesovsky <kendy@collabora.com>2015-09-27 22:48:21 +0200
commitac6f8bc92b1abe995694602f43d8ad108b7030fb (patch)
treeae8ed9337704cd83ab10e4c9cce4b7e06aaa7e8e
parent5c26f79467e4c5f920b77a058aa079654c322c25 (diff)
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 <alexnivan@yahoo.com> during GSoC 2013 - thank you! Change-Id: I7839147e54c2f976988121a523331def9859f4c2
-rw-r--r--sw/inc/doc.hxx7
-rw-r--r--sw/inc/fesh.hxx7
-rw-r--r--sw/inc/swtable.hxx9
-rw-r--r--sw/inc/tblafmt.hxx7
-rw-r--r--sw/source/core/doc/docnew.cxx2
-rw-r--r--sw/source/core/doc/tblafmt.cxx23
-rw-r--r--sw/source/core/doc/tblrwcl.cxx5
-rw-r--r--sw/source/core/frmedt/fetab.cxx24
-rw-r--r--sw/source/ui/dbui/dbinsdlg.cxx2
-rw-r--r--sw/source/ui/table/tautofmt.cxx2
10 files changed, 80 insertions, 8 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 2ddcc2d73ff9..51631a337a22 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 a219ac1f6997..a41e119eef2f 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 8b42d9dfafbe..5f645e31311b 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 3503bb72eb51..500e2cad9cd7 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 d65ef4a2b97e..74ab1f130c9b 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 6d2f4e5be6e8..2b5cf7da6bfd 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 d96864db5114..9574e0ae88f8 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 473540375802..191ba23edca2 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 d84b7d041852..8d2f1dcda204 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 42e9042c3a39..6c127eb1366f 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 );
}