summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ivan <alexnivan@yahoo.com>2013-08-01 20:39:52 +0300
committerAlex Ivan <alexnivan@yahoo.com>2013-08-01 20:39:52 +0300
commitee61450df68e7cc539720d95c7f470f7b56c4cda (patch)
tree55c66d4b35def2f712443aa6d895b4e019e0e4c6
parent32ce2fc84491847d26576f3af454cb9e86cfc26a (diff)
Register SwFmts to correct parents for each element of table
Insert table, text to table and set autoformat methods now set the parent of each SwFmt to the correct element in the table style. For more complex tables, i.e. boxes contain other lines and so on, the parents for these are set to the same as the line/box in which they are found. Change-Id: I24bc35323414bc8bdceda610da7ba53da043f09b
-rw-r--r--sw/inc/swtblfmt.hxx5
-rw-r--r--sw/source/core/doc/swtblfmt.cxx95
-rw-r--r--sw/source/core/docnode/ndtbl.cxx23
3 files changed, 111 insertions, 12 deletions
diff --git a/sw/inc/swtblfmt.hxx b/sw/inc/swtblfmt.hxx
index 0443cbdb5e5c..e61a0bb4153f 100644
--- a/sw/inc/swtblfmt.hxx
+++ b/sw/inc/swtblfmt.hxx
@@ -124,6 +124,11 @@ public:
static void RestoreTableProperties( SwTableFmt* pSrcFmt, SwTable &table );
static SwTableFmt* StoreTableProperties( const SwTable &table );
+ static void AssignLineParents( SwTableFmt* pSrcFmt, SwTable &table );
+ static void AssignBoxParents( SwTableLineFmt* pSrcLineFmt, SwTableLine &line );
+ static void AssignLineParents_Complex( SwTableLineFmt* pSrcLineFmt, SwTableBoxFmt* pSrcBoxFmt, SwTableBox& rBox );
+ static void AssignBoxParents_Complex( SwTableLineFmt* pSrcLineFmt, SwTableBoxFmt* pSrcBoxFmt, SwTableLine& rLine );
+
sal_Bool Load( SvStream& rStream, const SwAfVersions& rVersions, SwDoc* pDoc, sal_uInt16 nVal );
TYPEINFO(); // Already in base class Content.
diff --git a/sw/source/core/doc/swtblfmt.cxx b/sw/source/core/doc/swtblfmt.cxx
index db24264196e3..c771894e7cd4 100644
--- a/sw/source/core/doc/swtblfmt.cxx
+++ b/sw/source/core/doc/swtblfmt.cxx
@@ -269,6 +269,8 @@ void SwTableFmt::RestoreTableProperties( SwTableFmt* pSrcFmt, SwTable &table )
else
pTableStyle->Remove( pHardFmt );
+ AssignLineParents( pSrcFmt, table );
+
SwEditShell *pShell = pDoc->GetEditShell();
pDoc->SetRowSplit( *pShell->getShellCrsr( false ), SwFmtRowSplit( bRowSplit ) );
@@ -284,6 +286,99 @@ SwTableFmt* SwTableFmt::StoreTableProperties( const SwTable &table )
return (SwTableFmt*)pHardFmt->GetRegisteredIn();
}
+void SwTableFmt::AssignLineParents( SwTableFmt* pSrcFmt, SwTable &rTable )
+{
+ sal_uInt16 nLines = rTable.GetTabLines().size();
+ for( sal_uInt16 n = 0; n < nLines; ++n )
+ {
+ SwTableLineFmt* pLineFmt = (SwTableLineFmt*)rTable.GetTabLines()[ n ]->GetFrmFmt();
+ SwTableLineFmt* pFmt = 0;
+
+ if( pSrcFmt )
+ {
+ if( !n )
+ pFmt = pSrcFmt->GetFirstLineFmt();
+ else if( n == nLines - 1 )
+ pFmt = pSrcFmt->GetLastLineFmt();
+ else if( n & 1 )
+ pFmt = pSrcFmt->GetEvenLineFmt();
+ else
+ pFmt = pSrcFmt->GetOddLineFmt();
+ }
+
+ if( pFmt )
+ pLineFmt->RegisterToFormat( *pFmt );
+ else if( pLineFmt->GetRegisteredIn() )
+ ((SwTableLineFmt*)pLineFmt->GetRegisteredIn())->Remove( pLineFmt );
+
+ AssignBoxParents( pFmt, *rTable.GetTabLines()[ n ] );
+ }
+}
+
+void SwTableFmt::AssignBoxParents( SwTableLineFmt* pSrcLineFmt, SwTableLine &rLine )
+{
+ sal_uInt16 nBoxes = rLine.GetTabBoxes().size();
+ for( sal_uInt16 n = 0; n < nBoxes; ++n )
+ {
+ SwTableBoxFmt* pBoxFmt = (SwTableBoxFmt*)rLine.GetTabBoxes()[ n ]->GetFrmFmt();
+ SwTableBoxFmt* pFmt = 0;
+
+ if( pSrcLineFmt )
+ {
+ if( !n )
+ pFmt = pSrcLineFmt->GetFirstBoxFmt();
+ else if( n == nBoxes - 1 )
+ pFmt = pSrcLineFmt->GetLastBoxFmt();
+ else if( n & 1 )
+ pFmt = pSrcLineFmt->GetEvenBoxFmt();
+ else
+ pFmt = pSrcLineFmt->GetOddBoxFmt();
+ }
+
+ if( pFmt )
+ pBoxFmt->RegisterToFormat( *pFmt );
+ else if( pBoxFmt->GetRegisteredIn() )
+ ((SwTableBoxFmt*)pBoxFmt->GetRegisteredIn())->Remove( pBoxFmt );
+
+
+ if( rLine.GetTabBoxes()[ n ]->GetTabLines().size() )
+ AssignLineParents_Complex( pSrcLineFmt, pFmt, *rLine.GetTabBoxes()[ n ] );
+ }
+}
+
+void SwTableFmt::AssignLineParents_Complex( SwTableLineFmt* pSrcLineFmt, SwTableBoxFmt* pSrcBoxFmt, SwTableBox& rBox )
+{
+ sal_uInt16 nLines = rBox.GetTabLines().size();
+ for( sal_uInt16 n = 0; n < nLines; ++n )
+ {
+ SwTableLineFmt* pLineFmt = (SwTableLineFmt*)rBox.GetTabLines()[ n ]->GetFrmFmt();
+
+ if( pSrcLineFmt )
+ pLineFmt->RegisterToFormat( *pSrcLineFmt );
+ else
+ ((SwTableLineFmt*)pLineFmt->GetRegisteredIn())->Remove( pLineFmt );
+
+ AssignBoxParents_Complex( pSrcLineFmt, pSrcBoxFmt, *rBox.GetTabLines()[ n ] );
+ }
+}
+
+void SwTableFmt::AssignBoxParents_Complex( SwTableLineFmt* pSrcLineFmt, SwTableBoxFmt* pSrcBoxFmt, SwTableLine& rLine )
+{
+ sal_uInt16 nBoxes = rLine.GetTabBoxes().size();
+ for( sal_uInt16 n = 0; n < nBoxes; ++n )
+ {
+ SwTableBoxFmt* pBoxFmt = (SwTableBoxFmt*)rLine.GetTabBoxes()[ n ]->GetFrmFmt();
+
+ if( pSrcBoxFmt )
+ pBoxFmt->RegisterToFormat( *pSrcBoxFmt );
+ else
+ ((SwTableBoxFmt*)pBoxFmt->GetRegisteredIn())->Remove( pBoxFmt );
+
+ if( rLine.GetTabBoxes()[ n ]->GetTabLines().size() )
+ AssignLineParents_Complex( pSrcLineFmt, pSrcBoxFmt, *rLine.GetTabBoxes()[ n ] );
+ }
+}
+
SwTableLineFmt::SwTableLineFmt( SwAttrPool& rPool, const sal_Char* pFmtNm,
SwFrmFmt *pDrvdFrm )
: SwFrmFmt( rPool, pFmtNm, pDrvdFrm, RES_FRMFMT, aTableLineSetRange )
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index a8635a33cac3..8b117c5d35e6 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -162,16 +162,11 @@ lcl_SetDfltBoxAttr(SwTableBox& rBox, DfltBoxAttrList_t & rBoxFmtArr,
pNewTableBoxFmt = pDoc->MakeTableBoxFmt();
pNewTableBoxFmt->SetFmtAttr( pBoxFrmFmt->GetAttrSet().Get( RES_FRM_SIZE ) );
- if( pAutoFmt )
- pAutoFmt->UpdateToSet( nId, (SfxItemSet&)pNewTableBoxFmt->GetAttrSet(),
- SwTableAutoFmt::UPDATE_BOX,
- pDoc->GetNumberFormatter( sal_True ) );
- else
- ::lcl_SetDfltBoxAttr( *pNewTableBoxFmt, nId );
+ ::lcl_SetDfltBoxAttr( *pNewTableBoxFmt, nId );
(*pMap)[pBoxFrmFmt] = pNewTableBoxFmt;
}
- rBox.ChgFrmFmt( pNewTableBoxFmt );
+ rBox.ChgFrmFmt( new SwTableBoxFmt( *pNewTableBoxFmt) );
}
static SwTableBoxFmt *lcl_CreateDfltBoxFmt( SwDoc &rDoc, std::vector<SwTableBoxFmt*> &rBoxFmtArr,
@@ -459,7 +454,7 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
SwTableLines& rLines = pNdTbl->GetTabLines();
for( sal_uInt16 n = 0; n < nRows; ++n )
{
- SwTableLine* pLine = new SwTableLine( pLineFmt, nCols, 0 );
+ SwTableLine* pLine = new SwTableLine( new SwTableLineFmt( *pLineFmt ), nCols, 0 );
rLines.insert( rLines.begin() + n, pLine );
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
for( sal_uInt16 i = 0; i < nCols; ++i )
@@ -468,10 +463,10 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
if( bDfltBorders )
{
sal_uInt8 nBoxId = (i < nCols - 1 ? 0 : 1) + (n ? 2 : 0 );
- pBoxF = ::lcl_CreateDfltBoxFmt( *this, aBoxFmtArr, nCols, nBoxId);
+ pBoxF = new SwTableBoxFmt( *::lcl_CreateDfltBoxFmt( *this, aBoxFmtArr, nCols, nBoxId) );
}
else
- pBoxF = pBoxFmt;
+ pBoxF = new SwTableBoxFmt( *pBoxFmt );
// For AutoFormat on input: the columns are set when inserting the Table
// The Array contains the columns positions and not their widths!
@@ -495,6 +490,9 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
aNdIdx += 3; // StartNode, TextNode, EndNode == 3 Nodes
}
}
+
+ SwTableFmt::AssignLineParents( pTableStyle, *pNdTbl );
+
// Insert Frms
GetNodes().GoNext( &aNdIdx ); // Go to the next ContentNode
pTblNd->MakeFrms( &aNdIdx );
@@ -739,8 +737,7 @@ const SwTable* SwDoc::TextToTable( const SwInsertTableOptions& rInsTblOpts,
else
{
bChgSz = 0 == (*aBoxFmtArr2)[ nId ];
- pBoxF = ::lcl_CreateDfltBoxFmt( *this, *aBoxFmtArr2,
- USHRT_MAX, nId );
+ pBoxF = new SwTableBoxFmt ( *::lcl_CreateDfltBoxFmt( *this, *aBoxFmtArr2, USHRT_MAX, nId ) );
if( bChgSz )
pBoxF->SetFmtAttr( pBox->GetFrmFmt()->GetFrmSize() );
pBox->ChgFrmFmt( pBoxF );
@@ -749,6 +746,8 @@ const SwTable* SwDoc::TextToTable( const SwInsertTableOptions& rInsTblOpts,
}
}
+ SwTableFmt::AssignLineParents( pTableStyle, *pNdTbl );
+
// Check the Boxes' for Numbers
if( IsInsTblFormatNum() )
{