[Libreoffice-commits] core.git: Branch 'feature/table-style' - 2 commits - sw/source
Alex Ivan
alexnivan at yahoo.com
Wed Jul 24 10:28:18 PDT 2013
sw/source/core/doc/tblafmt.cxx | 43 +++++++++++++++
sw/source/core/docnode/ndtbl.cxx | 109 ++++++++++++++++++++++++++++++++-------
2 files changed, 133 insertions(+), 19 deletions(-)
New commits:
commit 4887943a2c33475640d1dfed7c2d249e463f714f
Author: Alex Ivan <alexnivan at yahoo.com>
Date: Wed Jul 24 20:09:45 2013 +0300
Fix table styles not loading
Some unused properties were no longer loaded and that messed
up the styles, breaking the first and not loading the others.
Information about font is not loaded properly and selecting one
of the styles for a table causes an error.
Things will most likely be changed again since the targeted ideal
is to create the styles with the document.
Change-Id: I17a2c2c2f4eff36265489f725a83a4317b27339e
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index 7a09fa1..3792f1b 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -354,6 +354,17 @@ sal_Bool SwTableBoxFmt::Load( SvStream& rStream, const SwAfVersions& rVersions,
READ( aBox, SvxBoxItem, rVersions.nBoxVersion )
SetBox( aBox );
+ // Unused, but needed to be loaded to not mess the other styles
+ if( nVer >= AUTOFORMAT_DATA_ID_680DR14 )
+ {
+ SvxLineItem aTLBR( 0 );
+ READ( aTLBR, SvxLineItem, rVersions.nLineVersion)
+
+ SvxLineItem aBLTR( 0 );
+ READ( aBLTR, SvxLineItem, rVersions.nLineVersion)
+ }
+ // <- close
+
SvxBrushItem aBackground = SvxBrushItem( RES_BACKGROUND );
READ( aBackground, SvxBrushItem, rVersions.nBrushVersion )
SetBackground( aBackground );
@@ -374,6 +385,38 @@ sal_Bool SwTableBoxFmt::Load( SvStream& rStream, const SwAfVersions& rVersions,
SetVerticalAlignment( aVerticalAlignment );
}
+ // Unused, but needed to be loaded to not mess the other styles
+ SvxHorJustifyItem aHorJustify( SVX_HOR_JUSTIFY_STANDARD, 0 );
+ READ( aHorJustify, SvxHorJustifyItem, rVersions.nHorJustifyVersion )
+
+ SvxVerJustifyItem aVerJustify( SVX_VER_JUSTIFY_STANDARD, 0 );
+ READ( aVerJustify, SvxVerJustifyItem, rVersions.nVerJustifyVersion )
+
+ SvxOrientationItem aOrientation( SVX_ORIENTATION_STANDARD, 0 );
+ READ( aOrientation, SvxOrientationItem, rVersions.nOrientationVersion )
+
+ SvxMarginItem aMargin( 0 );
+ READ( aMargin, SvxMarginItem, rVersions.nMarginVersion )
+
+ SfxBoolItem aLinebreak( 0 );
+ pNew = aLinebreak.Create(rStream, rVersions.nBoolVersion );
+ aLinebreak.SetValue( ((SfxBoolItem*)pNew)->GetValue() );
+ delete pNew;
+
+ if ( nVer >= AUTOFORMAT_DATA_ID_504 )
+ {
+ SfxInt32Item aRotateAngle( 0 );
+ pNew = aRotateAngle.Create( rStream, rVersions.nInt32Version );
+ aRotateAngle.SetValue( ((SfxInt32Item*)pNew)->GetValue() );
+ delete pNew;
+
+ SvxRotateModeItem aRotateMode( SVX_ROTATE_MODE_STANDARD, 0 );
+ pNew = aRotateMode.Create( rStream, rVersions.nRotateModeVersion );
+ aRotateMode.SetValue( ((SvxRotateModeItem*)pNew)->GetValue() );
+ delete pNew;
+ }
+ // <- close
+
if( 0 == rVersions.nNumFmtVersion )
{
sal_uInt16 eSys, eLge;
commit eccd75596b8e8c1993be94151593b598a1031928
Author: Alex Ivan <alexnivan at yahoo.com>
Date: Wed Jul 24 20:04:22 2013 +0300
Added some properties back into hard format
In ligth of recent changes, some of the properties that had
been previously removed were now added back into the hard
format.
Change-Id: I4b25cc8415a19e84d9391f59a132b63d38a55188
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index cefcef2..60254e5 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -134,16 +134,59 @@ static void lcl_SetDfltBoxAttr( SwFrmFmt& rFmt, sal_uInt8 nId )
rFmt.SetFmtAttr( aBox );
}
-static void lcl_SetDfltBorders( SwTableFmt* pFmt )
+typedef std::map<SwFrmFmt *, SwTableBoxFmt *> DfltBoxAttrMap_t;
+typedef std::vector<DfltBoxAttrMap_t *> DfltBoxAttrList_t;
+
+static void
+lcl_SetDfltBoxAttr(SwTableBox& rBox, DfltBoxAttrList_t & rBoxFmtArr,
+ sal_uInt8 const nId, SwTableAutoFmt const*const pAutoFmt = 0)
{
- for( sal_uInt8 n = 0; n < 4; ++n )
+ DfltBoxAttrMap_t * pMap = rBoxFmtArr[ nId ];
+ if (!pMap)
{
- for( sal_uInt8 i = 0; i < 4; i++ )
- {
- sal_uInt8 nId = (i < 3 ? 0 : 1) + (n ? 2 : 0);
- ::lcl_SetDfltBoxAttr( *pFmt->GetBoxFmt( 4 * n + i ), nId );
- }
+ pMap = new DfltBoxAttrMap_t;
+ rBoxFmtArr[ nId ] = pMap;
+ }
+
+ SwTableBoxFmt* pNewTableBoxFmt = 0;
+ SwFrmFmt* pBoxFrmFmt = rBox.GetFrmFmt();
+ DfltBoxAttrMap_t::iterator const iter(pMap->find(pBoxFrmFmt));
+ if (pMap->end() != iter)
+ {
+ pNewTableBoxFmt = iter->second;
+ }
+ else
+ {
+ SwDoc* pDoc = pBoxFrmFmt->GetDoc();
+ // format does not exist, so create it
+ 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 );
+
+ (*pMap)[pBoxFrmFmt] = pNewTableBoxFmt;
+ }
+ rBox.ChgFrmFmt( pNewTableBoxFmt );
+}
+
+static SwTableBoxFmt *lcl_CreateDfltBoxFmt( SwDoc &rDoc, std::vector<SwTableBoxFmt*> &rBoxFmtArr,
+ sal_uInt16 nCols, sal_uInt8 nId )
+{
+ if ( !rBoxFmtArr[nId] )
+ {
+ SwTableBoxFmt* pBoxFmt = rDoc.MakeTableBoxFmt();
+ if( USHRT_MAX != nCols )
+ pBoxFmt->SetFmtAttr( SwFmtFrmSize( ATT_VAR_SIZE,
+ USHRT_MAX / nCols, 0 ));
+ ::lcl_SetDfltBoxAttr( *pBoxFmt, nId );
+ rBoxFmtArr[ nId ] = pBoxFmt;
}
+ return rBoxFmtArr[nId];
}
SwTableNode* SwDoc::IsIdxInTbl(const SwNodeIndex& rIdx)
@@ -396,15 +439,22 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
}
}
- if( !pTAFmt && bDfltBorders )
- ::lcl_SetDfltBorders( pTableFmt );
-
SwTable * pNdTbl = &pTblNd->GetTable();
pNdTbl->RegisterToFormat( *pTableFmt );
pNdTbl->SetRowsToRepeat( nRowsToRepeat );
pNdTbl->SetTableModel( bNewModel );
+ std::vector<SwTableBoxFmt*> aBoxFmtArr;
+ SwTableBoxFmt* pBoxFmt = 0;
+ if( !bDfltBorders )
+ {
+ pBoxFmt = MakeTableBoxFmt();
+ pBoxFmt->SetFmtAttr( SwFmtFrmSize( ATT_VAR_SIZE, USHRT_MAX / nCols, 0 ));
+ }
+ else
+ aBoxFmtArr.resize( 4, NULL );
+
SwNodeIndex aNdIdx( *pTblNd, 1 ); // Set to StartNode of first Box
SwTableLines& rLines = pNdTbl->GetTabLines();
for( sal_uInt16 n = 0; n < nRows; ++n )
@@ -414,10 +464,14 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
for( sal_uInt16 i = 0; i < nCols; ++i )
{
- SwTableBoxFmt *pBoxF = MakeTableBoxFmt();
- if( USHRT_MAX != nCols )
- pBoxF->SetFmtAttr( SwFmtFrmSize( ATT_VAR_SIZE,
- USHRT_MAX / nCols, 0 ) );
+ SwTableBoxFmt *pBoxF;
+ if( bDfltBorders )
+ {
+ sal_uInt8 nBoxId = (i < nCols - 1 ? 0 : 1) + (n ? 2 : 0 );
+ pBoxF = ::lcl_CreateDfltBoxFmt( *this, aBoxFmtArr, nCols, nBoxId);
+ }
+ else
+ pBoxF = pBoxFmt;
// For AutoFormat on input: the columns are set when inserting the Table
// The Array contains the columns positions and not their widths!
@@ -655,10 +709,19 @@ const SwTable* SwDoc::TextToTable( const SwInsertTableOptions& rInsTblOpts,
if( rInsTblOpts.mnInsMode & tabopts::DEFAULT_BORDER )
{
- if( !pTAFmt )
- ::lcl_SetDfltBorders( pTableFmt );
+ sal_uInt8 nBoxArrLen = 4;
+ boost::scoped_ptr< DfltBoxAttrList_t > aBoxFmtArr1;
+ boost::scoped_ptr< std::vector<SwTableBoxFmt*> > aBoxFmtArr2;
+ if( bUseBoxFmt )
+ {
+ aBoxFmtArr1.reset(new DfltBoxAttrList_t( nBoxArrLen, NULL ));
+ }
+ else
+ {
+ aBoxFmtArr2.reset(new std::vector<SwTableBoxFmt*>( nBoxArrLen, NULL ));
+ }
- SwTableBoxFmt *pBoxF = MakeTableBoxFmt();
+ SwTableBoxFmt *pBoxF = 0;
SwTableLines& rLines = pNdTbl->GetTabLines();
sal_uInt16 nRows = rLines.size();
for( sal_uInt16 n = 0; n < nRows; ++n )
@@ -668,10 +731,18 @@ const SwTable* SwDoc::TextToTable( const SwInsertTableOptions& rInsTblOpts,
for( sal_uInt16 i = 0; i < nCols; ++i )
{
SwTableBox* pBox = rBoxes[ i ];
+ bool bChgSz = false;
- if( !bUseBoxFmt )
+ sal_uInt8 nId = (i < nCols - 1 ? 0 : 1) + (n ? 2 : 0 );
+ if( bUseBoxFmt )
+ ::lcl_SetDfltBoxAttr( *pBox, *aBoxFmtArr1, nId );
+ else
{
- pBoxF->SetFmtAttr( pBox->GetFrmFmt()->GetFrmSize() );
+ bChgSz = 0 == (*aBoxFmtArr2)[ nId ];
+ pBoxF = ::lcl_CreateDfltBoxFmt( *this, *aBoxFmtArr2,
+ USHRT_MAX, nId );
+ if( bChgSz )
+ pBoxF->SetFmtAttr( pBox->GetFrmFmt()->GetFrmSize() );
pBox->ChgFrmFmt( pBoxF );
}
}
More information about the Libreoffice-commits
mailing list