[Libreoffice-commits] core.git: Branch 'feature/table-style' - sw/inc sw/source
Alex Ivan
alexnivan at yahoo.com
Tue Jun 25 04:27:12 PDT 2013
Rebased ref, commits from common ancestor:
commit e303aa5e568707cfb3a35315dbb645fc7d950e74
Author: Alex Ivan <alexnivan at yahoo.com>
Date: Tue Jun 25 14:22:06 2013 +0300
Revert prev changes; add SwTableFmt to Autoformat
Changes made in previous patch have been reverted.
A SwTableFmt memeber has been added to SwTableAutoFmt in
order to enable gradual transfer of items from one to
the other, while maintaining current functionality.
Change-Id: I844f77914277ed6f5e115aa82f41e753589c7057
diff --git a/sw/inc/tblafmt.hxx b/sw/inc/tblafmt.hxx
index 7340427..1988933 100644
--- a/sw/inc/tblafmt.hxx
+++ b/sw/inc/tblafmt.hxx
@@ -233,6 +233,7 @@ class SW_DLLPUBLIC SwTableAutoFmt
friend void _FinitCore(); // To destroy dflt. pointer.
static SwBoxAutoFmt* pDfltBoxAutoFmt;
+ SwTableFmt* m_pTableStyle;
String aName;
sal_uInt16 nStrResId;
@@ -259,7 +260,7 @@ class SW_DLLPUBLIC SwTableAutoFmt
SvxShadowItem m_aShadow;
public:
- SwTableAutoFmt( const String& rName );
+ SwTableAutoFmt( const String& rName, SwTableFmt* pTableStyle );
SwTableAutoFmt( const SwTableAutoFmt& rNew );
~SwTableAutoFmt();
@@ -293,7 +294,7 @@ public:
void SetValueFormat( const sal_Bool bNew ) { bInclValueFormat = bNew; }
void SetWidthHeight( const sal_Bool bNew ) { bInclWidthHeight = bNew; }
- sal_Bool Load( SvStream& rStream, const SwAfVersions& );
+ static SwTableAutoFmt* Load( SvStream& rStream, const SwAfVersions&, SwDoc* pDoc );
sal_Bool Save( SvStream& rStream, sal_uInt16 fileVersion ) const;
};
@@ -301,12 +302,13 @@ class SW_DLLPUBLIC SwTableAutoFmtTbl
{
struct Impl;
::boost::scoped_ptr<Impl> m_pImpl;
+ SwDoc* m_pDoc;
SW_DLLPRIVATE sal_Bool Load( SvStream& rStream );
SW_DLLPRIVATE sal_Bool Save( SvStream& rStream ) const;
public:
- explicit SwTableAutoFmtTbl();
+ explicit SwTableAutoFmtTbl(SwDoc* pDoc);
~SwTableAutoFmtTbl();
size_t size() const;
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index 2031563..bb4e682 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -590,8 +590,9 @@ sal_Bool SwBoxAutoFmt::SaveVersionNo( SvStream& rStream, sal_uInt16 fileVersion
-SwTableAutoFmt::SwTableAutoFmt( const String& rName )
- : aName( rName )
+SwTableAutoFmt::SwTableAutoFmt( const String& rName, SwTableFmt* pTableStyle )
+ : m_pTableStyle( pTableStyle )
+ , aName( rName )
, nStrResId( USHRT_MAX )
, m_aBreak( SVX_BREAK_NONE, RES_BREAK )
, m_aKeepWithNextPara( sal_False, RES_KEEP )
@@ -639,6 +640,7 @@ SwTableAutoFmt& SwTableAutoFmt::operator=( const SwTableAutoFmt& rNew )
aBoxAutoFmt[ n ] = 0;
}
+ m_pTableStyle = rNew.m_pTableStyle;
aName = rNew.aName;
nStrResId = rNew.nStrResId;
bInclFont = rNew.bInclFont;
@@ -913,8 +915,10 @@ void SwTableAutoFmt::StoreTableProperties(const SwTable &table)
m_aShadow = static_cast<const SvxShadowItem&>(rSet.Get(RES_SHADOW));
}
-sal_Bool SwTableAutoFmt::Load( SvStream& rStream, const SwAfVersions& rVersions )
+SwTableAutoFmt* SwTableAutoFmt::Load( SvStream& rStream, const SwAfVersions& rVersions, SwDoc* pDoc )
{
+ SwTableAutoFmt* pRet = NULL;
+
sal_uInt16 nVal = 0;
rStream >> nVal;
sal_Bool bRet = 0 == rStream.GetError();
@@ -925,7 +929,8 @@ sal_Bool SwTableAutoFmt::Load( SvStream& rStream, const SwAfVersions& rVersions
sal_Bool b;
// --- from 680/dr25 on: store strings as UTF-8
CharSet eCharSet = (nVal >= AUTOFORMAT_ID_680DR25) ? RTL_TEXTENCODING_UTF8 : rStream.GetStreamCharSet();
- aName = rStream.ReadUniOrByteString( eCharSet );
+ OUString aName = rStream.ReadUniOrByteString( eCharSet );
+ sal_uInt16 nStrResId = USHRT_MAX;
if( AUTOFORMAT_DATA_ID_552 <= nVal )
{
rStream >> nStrResId;
@@ -938,24 +943,34 @@ sal_Bool SwTableAutoFmt::Load( SvStream& rStream, const SwAfVersions& rVersions
else
nStrResId = USHRT_MAX;
}
- rStream >> b; bInclFont = b;
- rStream >> b; bInclJustify = b;
- rStream >> b; bInclFrame = b;
- rStream >> b; bInclBackground = b;
- rStream >> b; bInclValueFormat = b;
- rStream >> b; bInclWidthHeight = b;
+
+ // FIXME Yuk! we are creating the table styles ATM, but in the targetted
+ // ideal, the table styles are created with the document
+ SwTableFmt* pStyle = pDoc->FindTblFmtByName(aName);
+ if ( !pStyle )
+ pStyle = pDoc->MakeTblFrmFmt(aName, NULL);
+ pRet = new SwTableAutoFmt( aName, pStyle );
+
+ pRet->nStrResId = nStrResId;
+
+ rStream >> b; pRet->bInclFont = b;
+ rStream >> b; pRet->bInclJustify = b;
+ rStream >> b; pRet->bInclFrame = b;
+ rStream >> b; pRet->bInclBackground = b;
+ rStream >> b; pRet->bInclValueFormat = b;
+ rStream >> b; pRet->bInclWidthHeight = b;
if (nVal >= AUTOFORMAT_DATA_ID_31005 && WriterSpecificBlockExists(rStream))
{
SfxPoolItem* pNew = 0;
- READ(m_aBreak, SvxFmtBreakItem, AUTOFORMAT_FILE_VERSION);
- READ(m_aPageDesc, SwFmtPageDesc, AUTOFORMAT_FILE_VERSION);
- READ(m_aKeepWithNextPara, SvxFmtKeepItem, AUTOFORMAT_FILE_VERSION);
+ READ(pRet->m_aBreak, SvxFmtBreakItem, AUTOFORMAT_FILE_VERSION);
+ READ(pRet->m_aPageDesc, SwFmtPageDesc, AUTOFORMAT_FILE_VERSION);
+ READ(pRet->m_aKeepWithNextPara, SvxFmtKeepItem, AUTOFORMAT_FILE_VERSION);
- rStream >> m_aRepeatHeading >> m_bLayoutSplit >> m_bRowSplit >> m_bCollapsingBorders;
+ rStream >> pRet->m_aRepeatHeading >> pRet->m_bLayoutSplit >> pRet->m_bRowSplit >> pRet->m_bCollapsingBorders;
- READ(m_aShadow, SvxShadowItem, AUTOFORMAT_FILE_VERSION);
+ READ(pRet->m_aShadow, SvxShadowItem, AUTOFORMAT_FILE_VERSION);
}
bRet = 0 == rStream.GetError();
@@ -965,7 +980,7 @@ sal_Bool SwTableAutoFmt::Load( SvStream& rStream, const SwAfVersions& rVersions
SwBoxAutoFmt* pFmt = new SwBoxAutoFmt;
bRet = pFmt->Load( rStream, rVersions, nVal );
if( bRet )
- aBoxAutoFmt[ i ] = pFmt;
+ pRet->aBoxAutoFmt[ i ] = pFmt;
else
{
delete pFmt;
@@ -973,7 +988,12 @@ sal_Bool SwTableAutoFmt::Load( SvStream& rStream, const SwAfVersions& rVersions
}
}
}
- return bRet;
+ if ( !bRet )
+ {
+ delete pRet;
+ pRet = NULL;
+ }
+ return pRet;
}
sal_Bool SwTableAutoFmt::Save( SvStream& rStream, sal_uInt16 fileVersion ) const
@@ -1060,12 +1080,18 @@ SwTableAutoFmtTbl::~SwTableAutoFmtTbl()
{
}
-SwTableAutoFmtTbl::SwTableAutoFmtTbl()
+SwTableAutoFmtTbl::SwTableAutoFmtTbl(SwDoc* pDoc)
: m_pImpl(new Impl)
+ , m_pDoc( pDoc)
{
String sNm;
- SwTableAutoFmt* pNew = new SwTableAutoFmt(
- SwStyleNameMapper::GetUIName( RES_POOLCOLL_STANDARD, sNm ) );
+ // FIXME Yuk! we are creating the table styles ATM, but in the targetted
+ // ideal, the table styles are created with the document
+ SwStyleNameMapper::GetUIName( RES_POOLCOLL_STANDARD, sNm );
+ SwTableFmt* pStyle = pDoc->FindTblFmtByName(sNm);
+ if ( !pStyle )
+ pStyle = pDoc->MakeTblFrmFmt(sNm, NULL);
+ SwTableAutoFmt* pNew = new SwTableAutoFmt( sNm, pStyle );
SwBoxAutoFmt aNew;
@@ -1191,15 +1217,14 @@ sal_Bool SwTableAutoFmtTbl::Load( SvStream& rStream )
for( sal_uInt16 i = 0; i < nAnz; ++i )
{
- pNew = new SwTableAutoFmt( aEmptyStr );
- bRet = pNew->Load( rStream, aVersions );
- if( bRet )
+ pNew = SwTableAutoFmt::Load( rStream, aVersions, m_pDoc );
+ if( pNew )
{
m_pImpl->m_AutoFormats.push_back(pNew);
}
else
{
- delete pNew;
+ bRet = false;
break;
}
}
diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx
index 49fc1a3..ff5757d 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -2993,7 +2993,7 @@ void SwXTextTable::autoFormat(const OUString& aName) throw( lang::IllegalArgumen
{
String sAutoFmtName(aName);
- SwTableAutoFmtTbl aAutoFmtTbl;
+ SwTableAutoFmtTbl aAutoFmtTbl( pFmt->GetDoc() );
aAutoFmtTbl.Load();
for (sal_uInt16 i = aAutoFmtTbl.size(); i;)
if( sAutoFmtName == aAutoFmtTbl[ --i ].GetName() )
diff --git a/sw/source/ui/dbui/dbinsdlg.cxx b/sw/source/ui/dbui/dbinsdlg.cxx
index 8de8676..0df3f70 100644
--- a/sw/source/ui/dbui/dbinsdlg.cxx
+++ b/sw/source/ui/dbui/dbinsdlg.cxx
@@ -1804,7 +1804,8 @@ void SwInsertDBColAutoPilot::Load()
if( sTmp.Len() )
{
// then load the AutoFmt file and look for Autoformat first
- SwTableAutoFmtTbl aAutoFmtTbl;
+ SwDoc* pDoc = pView->GetWrtShell().GetDoc();
+ SwTableAutoFmtTbl aAutoFmtTbl(pDoc);
aAutoFmtTbl.Load();
for( sal_uInt16 nAutoFmt = aAutoFmtTbl.size(); nAutoFmt; )
if( sTmp == aAutoFmtTbl[ --nAutoFmt ].GetName() )
diff --git a/sw/source/ui/shells/basesh.cxx b/sw/source/ui/shells/basesh.cxx
index dc54ec3..5c08e63 100644
--- a/sw/source/ui/shells/basesh.cxx
+++ b/sw/source/ui/shells/basesh.cxx
@@ -781,7 +781,7 @@ void SwBaseShell::Execute(SfxRequest &rReq)
{
String sAutoFmt = static_cast< const SfxStringItem* >(pItem)->GetValue();
- pAutoFmtTbl = new SwTableAutoFmtTbl;
+ pAutoFmtTbl = new SwTableAutoFmtTbl(GetShell().GetDoc());
pAutoFmtTbl->Load();
for( sal_uInt16 i = 0, nCount = pAutoFmtTbl->size(); i < nCount; i++ )
@@ -2558,7 +2558,7 @@ void SwBaseShell::InsertTable( SfxRequest& _rRequest )
aAutoName = pAuto->GetValue();
if ( aAutoName.Len() )
{
- SwTableAutoFmtTbl aTableTbl;
+ SwTableAutoFmtTbl aTableTbl(GetShell().GetDoc());
aTableTbl.Load();
for ( sal_uInt16 n=0; n<aTableTbl.size(); n++ )
{
diff --git a/sw/source/ui/table/tautofmt.cxx b/sw/source/ui/table/tautofmt.cxx
index aa93c35..dd1ec58 100644
--- a/sw/source/ui/table/tautofmt.cxx
+++ b/sw/source/ui/table/tautofmt.cxx
@@ -36,6 +36,9 @@
#include "tblafmt.hxx"
#include "tautofmt.hxx"
#include "shellres.hxx"
+#include "doc.hxx"
+#include "SwStyleNameMapper.hxx"
+#include "poolfmt.hxx"
using namespace com::sun::star;
@@ -56,7 +59,7 @@ protected:
virtual void Paint( const Rectangle& rRect );
private:
- SwTableAutoFmt aCurData;
+ SwTableAutoFmt* pCurData;
VirtualDevice aVD;
SvtScriptedTextHelper aScriptedText;
svx::frame::Array maArray; /// Implementation to draw the frame borders.
@@ -166,7 +169,7 @@ SwAutoFormatDlg::SwAutoFormatDlg( Window* pParent, SwWrtShell* pWrtShell,
m_pWndPreview->DetectRTL(pWrtShell);
- pTableTbl = new SwTableAutoFmtTbl;
+ pTableTbl = new SwTableAutoFmtTbl(pWrtShell->GetDoc());
pTableTbl->Load();
Init(pSelFmt);
@@ -307,8 +310,12 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, AddHdl)
if( n >= pTableTbl->size() )
{
// Format with the name does not already exist, so take up.
+ SwDoc* pDoc = pShell->GetDoc();
+ SwTableFmt* pStyle = pDoc->FindTblFmtByName( aFormatName );
+ if ( !pStyle )
+ pStyle = pDoc->MakeTblFrmFmt( aFormatName, NULL);
SwTableAutoFmt* pNewData = new
- SwTableAutoFmt( aFormatName );
+ SwTableAutoFmt( aFormatName, pStyle );
pShell->GetTableAutoFmt( *pNewData );
// Insert sorted!!
@@ -467,7 +474,14 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, SelFmtHdl)
{
nIndex = 255;
- SwTableAutoFmt aTmp( ViewShell::GetShellRes()->aStrNone );
+ String sNm;
+ // FIXME Yuk! we are creating the table styles ATM, but in the targetted
+ // ideal, the table styles are created with the document
+ SwStyleNameMapper::GetUIName( RES_POOLCOLL_STANDARD, sNm );
+ SwTableFmt* pStyle = pShell->GetDoc()->FindTblFmtByName(sNm);
+ if ( !pStyle )
+ pStyle = pShell->GetDoc()->MakeTblFrmFmt(sNm, NULL);
+ SwTableAutoFmt aTmp( sNm, pStyle );
aTmp.SetFont( sal_False );
aTmp.SetJustify( sal_False );
aTmp.SetFrame( sal_False );
@@ -499,7 +513,7 @@ IMPL_LINK_NOARG_INLINE_END(SwAutoFormatDlg, OkHdl)
AutoFmtPreview::AutoFmtPreview(Window* pParent) :
Window ( pParent ),
- aCurData ( aEmptyStr ),
+ pCurData ( NULL ),
aVD ( *this ),
aScriptedText ( aVD ),
bFitWidth ( sal_False ),
@@ -531,7 +545,7 @@ void AutoFmtPreview::Resize()
nDataColWidth1 = (aPrvSize.Width() - 4 - 2 * nLabelColWidth) / 3;
nDataColWidth2 = (aPrvSize.Width() - 4 - 2 * nLabelColWidth) / 4;
nRowHeight = (aPrvSize.Height() - 4) / 5;
- NotifyChange(aCurData);
+ NotifyChange(*pCurData);
}
void AutoFmtPreview::DetectRTL(SwWrtShell* pWrtShell)
@@ -569,7 +583,7 @@ rCTLFont.MethodName( Value );
void AutoFmtPreview::MakeFonts( sal_uInt8 nIndex, Font& rFont, Font& rCJKFont, Font& rCTLFont )
{
- const SwBoxAutoFmt& rBoxFmt = aCurData.GetBoxFmt( nIndex );
+ const SwBoxAutoFmt& rBoxFmt = pCurData->GetBoxFmt( nIndex );
rFont = rCJKFont = rCTLFont = GetFont();
Size aFontSize( rFont.GetSize().Width(), 10 );
@@ -603,7 +617,7 @@ sal_uInt8 AutoFmtPreview::GetFormatIndex( size_t nCol, size_t nRow ) const
const SvxBoxItem& AutoFmtPreview::GetBoxItem( size_t nCol, size_t nRow ) const
{
- return aCurData.GetBoxFmt( GetFormatIndex( nCol, nRow ) ).GetBox();
+ return pCurData->GetBoxFmt( GetFormatIndex( nCol, nRow ) ).GetBox();
}
void AutoFmtPreview::DrawString( size_t nCol, size_t nRow )
@@ -649,10 +663,10 @@ void AutoFmtPreview::DrawString( size_t nCol, size_t nRow )
case 23: nVal = 39; nNum = 13; goto MAKENUMSTR;
case 24: nVal = 108; nNum = 15; goto MAKENUMSTR;
MAKENUMSTR:
- if( aCurData.IsValueFormat() )
+ if( pCurData->IsValueFormat() )
{
String sFmt; LanguageType eLng, eSys;
- aCurData.GetBoxFmt( (sal_uInt8)nNum ).GetValueFormat( sFmt, eLng, eSys );
+ pCurData->GetBoxFmt( (sal_uInt8)nNum ).GetValueFormat( sFmt, eLng, eSys );
short nType;
bool bNew;
@@ -678,7 +692,7 @@ MAKENUMSTR:
Size theMaxStrSize( cellRect.GetWidth() - FRAME_OFFSET,
cellRect.GetHeight() - FRAME_OFFSET );
- if( aCurData.IsFont() )
+ if( pCurData->IsFont() )
{
Font aFont, aCJKFont, aCTLFont;
MakeFonts( nFmtIndex, aFont, aCJKFont, aCTLFont );
@@ -690,7 +704,7 @@ MAKENUMSTR:
aScriptedText.SetText( cellString, m_xBreak );
aStrSize = aScriptedText.GetTextSize();
- if( aCurData.IsFont() &&
+ if( pCurData->IsFont() &&
theMaxStrSize.Height() < aStrSize.Height() )
{
// If the string in this font does not
@@ -718,11 +732,11 @@ MAKENUMSTR:
// horizontal
if( mbRTL )
aPos.X() += nRightX;
- else if (aCurData.IsJustify())
+ else if (pCurData->IsJustify())
{
sal_uInt16 nHorPos = (sal_uInt16)
((cellRect.GetWidth()-aStrSize.Width())/2);
- const SvxAdjustItem& rAdj = aCurData.GetBoxFmt(nFmtIndex).GetAdjust();
+ const SvxAdjustItem& rAdj = pCurData->GetBoxFmt(nFmtIndex).GetAdjust();
switch ( rAdj.GetAdjust() )
{
case SVX_ADJUST_LEFT:
@@ -770,7 +784,7 @@ void AutoFmtPreview::DrawBackground()
{
for( size_t nCol = 0; nCol < 5; ++nCol )
{
- SvxBrushItem aBrushItem( aCurData.GetBoxFmt( GetFormatIndex( nCol, nRow ) ).GetBackground() );
+ SvxBrushItem aBrushItem( pCurData->GetBoxFmt( GetFormatIndex( nCol, nRow ) ).GetBackground() );
aVD.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
aVD.SetLineColor();
@@ -784,14 +798,14 @@ void AutoFmtPreview::DrawBackground()
void AutoFmtPreview::PaintCells()
{
// 1) background
- if ( aCurData.IsBackground() )
+ if ( pCurData->IsBackground() )
DrawBackground();
// 2) values
DrawStrings();
// 3) border
- if ( aCurData.IsFrame() )
+ if ( pCurData->IsFrame() )
maArray.DrawArray( aVD );
}
@@ -852,8 +866,8 @@ void AutoFmtPreview::CalcLineMap()
void AutoFmtPreview::NotifyChange( const SwTableAutoFmt& rNewData )
{
- aCurData = rNewData;
- bFitWidth = aCurData.IsJustify();//sal_True; //???
+ pCurData = const_cast< SwTableAutoFmt* >( &rNewData );
+ bFitWidth = pCurData->IsJustify();//sal_True; //???
CalcCellArray( bFitWidth );
CalcLineMap();
DoPaint( Rectangle( Point(0,0), GetSizePixel() ) );
More information about the Libreoffice-commits
mailing list