include/xmloff/xmlnume.hxx | 21 include/xmloff/xmlnumi.hxx | 12 sw/Library_sw.mk | 1 sw/inc/unosett.hxx | 14 sw/qa/extras/rtfimport/data/unbalanced-columns.rtf | 5 sw/qa/extras/rtfimport/rtfimport.cxx | 8 sw/source/core/unocore/unosett.cxx | 439 +++++++++--------- sw/source/ui/misc/outline.cxx | 4 sw/source/uibase/config/StoredChapterNumbering.cxx | 496 +++++++++++++++++++++ sw/source/uibase/config/uinums.cxx | 404 ++--------------- sw/source/uibase/inc/uinums.hxx | 51 +- writerfilter/source/rtftok/rtfdocumentimpl.cxx | 6 xmloff/source/draw/XMLShapePropertySetContext.cxx | 2 xmloff/source/draw/XMLShapeStyleContext.cxx | 2 xmloff/source/style/xmlnumi.cxx | 20 15 files changed, 858 insertions(+), 627 deletions(-)
New commits: commit f4bb73164a51ec83fe1d5975b1232d35f8a9e88a Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Sat Nov 8 22:47:26 2014 +0100 fdo#84645 RTF import: set DontBalanceTextColumns=true for the last section ... ... if it has multiple columns. See commit d185204737031955c56a24356ed003d342548434 (DOCX import: set DontBalanceTextColumns=true for the last section, 2014-07-17) for the DOCX equivalent of this problem; this just adapts the RTF tokenizer to dmapper. Change-Id: Ib30f9b386e204b8b2987832ab17ee0cc53b3f0bc diff --git a/sw/qa/extras/rtfimport/data/unbalanced-columns.rtf b/sw/qa/extras/rtfimport/data/unbalanced-columns.rtf new file mode 100644 index 0000000..aa57e38 --- /dev/null +++ b/sw/qa/extras/rtfimport/data/unbalanced-columns.rtf @@ -0,0 +1,5 @@ +{\rtf1 +\cols2 +\pard\plain First paragraph.\par +Second paragraph.\par +} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 46e0843..54334b3 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -2068,6 +2068,14 @@ DECLARE_RTFIMPORT_TEST(testFdo82512, "fdo82512.rtf") CPPUNIT_ASSERT_EQUAL(style::BreakType_COLUMN_BEFORE, getProperty<style::BreakType>(getParagraph(2), "BreakType")); } +DECLARE_RTFIMPORT_TEST(testUnbalancedColumns, "unbalanced-columns.rtf") +{ + uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTextSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY); + // This was false, last section was balanced, but it's unbalanced in Word. + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xTextSections->getByIndex(0), "DontBalanceTextColumns")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 3c7b5d3..66b9eb3 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -611,6 +611,12 @@ void RTFDocumentImpl::sectBreak(bool bFinal = false) writerfilter::Reference<Properties>::Pointer_t const pProperties( new RTFReferenceProperties(aAttributes, aSprms) ); + + if (bFinal && !m_pSuperstream) + // This is the end of the document, not just the end of e.g. a header. + // This makes sure that dmapper can set DontBalanceTextColumns=true for this section if necessary. + Mapper().markLastSectionGroup(); + // The trick is that we send properties of the previous section right now, which will be exactly what dmapper expects. Mapper().props(pProperties); Mapper().endParagraphGroup(); commit 5fea6b760df32297f225b72c9e2c30d975e9142a Author: Michael Stahl <mst...@redhat.com> Date: Sat Nov 8 22:28:49 2014 +0100 sw: SwChapterNumRules::sFileName looks pretty constant Change-Id: Iaecaccab729e22ae9504d01c9974779cf1ab381b diff --git a/sw/source/uibase/config/uinums.cxx b/sw/source/uibase/config/uinums.cxx index 449d1df..d48b6cb 100644 --- a/sw/source/uibase/config/uinums.cxx +++ b/sw/source/uibase/config/uinums.cxx @@ -46,7 +46,6 @@ using namespace ::com::sun::star; */ SwChapterNumRules::SwChapterNumRules() - : sFileName(OUString(CHAPTER_FILENAME)) { Init(); } @@ -57,14 +56,14 @@ void SwChapterNumRules::Save() SvtPathOptions aPathOpt; aURL.SetSmartURL( aPathOpt.GetUserConfigPath() ); aURL.setFinalSlash(); - aURL.Append(sFileName); + aURL.Append(CHAPTER_FILENAME); SfxMedium aMedium( aURL.GetMainURL(INetURLObject::NO_DECODE), STREAM_WRITE ); SvStream* pStream = aMedium.GetOutStream(); bool bRet = (pStream && pStream->GetError() == 0); if (bRet) { - sw::ExportStoredChapterNumberingRules(*this, *pStream, sFileName); + sw::ExportStoredChapterNumberingRules(*this, *pStream,CHAPTER_FILENAME); pStream->Flush(); @@ -83,12 +82,13 @@ void SwChapterNumRules::Init() for(sal_uInt16 i = 0; i < nMaxRules; ++i ) pNumRules[i] = 0; - OUString sNm( sFileName ); + OUString sNm(CHAPTER_FILENAME); SvtPathOptions aOpt; if( aOpt.SearchFile( sNm, SvtPathOptions::PATH_USERCONFIG )) { SfxMedium aStrm( sNm, STREAM_STD_READ ); - sw::ImportStoredChapterNumberingRules(*this, *aStrm.GetInStream(), sFileName); + sw::ImportStoredChapterNumberingRules(*this, *aStrm.GetInStream(), + CHAPTER_FILENAME); } } diff --git a/sw/source/uibase/inc/uinums.hxx b/sw/source/uibase/inc/uinums.hxx index 60a9d23..5b2226f 100644 --- a/sw/source/uibase/inc/uinums.hxx +++ b/sw/source/uibase/inc/uinums.hxx @@ -85,7 +85,6 @@ public: enum { nMaxRules = MAX_NUM_RULES }; // currently 9 defined forms protected: SwNumRulesWithName *pNumRules[ MAX_NUM_RULES ]; - OUString sFileName; void Init(); void Save(); commit f8482195dfdebc820ea4d4c2a0cb9dc698172efe Author: Michael Stahl <mst...@redhat.com> Date: Sat Nov 8 22:26:45 2014 +0100 sw: SwChapterNumRules::bModified has become pointless Change-Id: I7d4937dab947b14d4885c548cd7a96ebaba23c60 diff --git a/sw/source/uibase/config/uinums.cxx b/sw/source/uibase/config/uinums.cxx index 025ad2f..449d1df 100644 --- a/sw/source/uibase/config/uinums.cxx +++ b/sw/source/uibase/config/uinums.cxx @@ -47,33 +47,28 @@ using namespace ::com::sun::star; SwChapterNumRules::SwChapterNumRules() : sFileName(OUString(CHAPTER_FILENAME)) - , - bModified( false ) { Init(); } void SwChapterNumRules::Save() { - if( bModified ) + INetURLObject aURL; + SvtPathOptions aPathOpt; + aURL.SetSmartURL( aPathOpt.GetUserConfigPath() ); + aURL.setFinalSlash(); + aURL.Append(sFileName); + + SfxMedium aMedium( aURL.GetMainURL(INetURLObject::NO_DECODE), STREAM_WRITE ); + SvStream* pStream = aMedium.GetOutStream(); + bool bRet = (pStream && pStream->GetError() == 0); + if (bRet) { - INetURLObject aURL; - SvtPathOptions aPathOpt; - aURL.SetSmartURL( aPathOpt.GetUserConfigPath() ); - aURL.setFinalSlash(); - aURL.Append(sFileName); - - SfxMedium aMedium( aURL.GetMainURL(INetURLObject::NO_DECODE), STREAM_WRITE ); - SvStream* pStream = aMedium.GetOutStream(); - bool bRet = (pStream && pStream->GetError() == 0); - if (bRet) - { - sw::ExportStoredChapterNumberingRules(*this, *pStream, sFileName); + sw::ExportStoredChapterNumberingRules(*this, *pStream, sFileName); - pStream->Flush(); + pStream->Flush(); - aMedium.Commit(); - } + aMedium.Commit(); } } @@ -106,7 +101,6 @@ void SwChapterNumRules::CreateEmptyNumRule(sal_uInt16 const nIndex) void SwChapterNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, sal_uInt16 nIdx) { - bModified = true; assert(nIdx < nMaxRules); if( !pNumRules[nIdx] ) pNumRules[nIdx] = new SwNumRulesWithName( rCopy ); diff --git a/sw/source/uibase/inc/uinums.hxx b/sw/source/uibase/inc/uinums.hxx index d01edec9..60a9d23 100644 --- a/sw/source/uibase/inc/uinums.hxx +++ b/sw/source/uibase/inc/uinums.hxx @@ -86,7 +86,6 @@ public: protected: SwNumRulesWithName *pNumRules[ MAX_NUM_RULES ]; OUString sFileName; - bool bModified; void Init(); void Save(); commit 65d762d8ca0545d2f77da24f9cefa5b3148ef384 Author: Michael Stahl <mst...@redhat.com> Date: Sat Nov 8 22:21:12 2014 +0100 sw: delete the SwChapterNumRules binary Load/Store implementation Loading the outline formats from a StarOffice 3 user profile went out of style. Change-Id: I4989fa043a616428fea3705a72dee67082bfc226 diff --git a/sw/source/uibase/config/uinums.cxx b/sw/source/uibase/config/uinums.cxx index d0d872f..025ad2f 100644 --- a/sw/source/uibase/config/uinums.cxx +++ b/sw/source/uibase/config/uinums.cxx @@ -17,34 +17,25 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <uinums.hxx> + #include <hintids.hxx> #include <svl/urihelper.hxx> -#include <osl/thread.h> #include <unotools/pathoptions.hxx> #include <tools/stream.hxx> #include <sfx2/docfile.hxx> #include <svl/itemiter.hxx> -#include <editeng/brushitem.hxx> #include <tools/resid.hxx> -#include <fmtornt.hxx> #include <swtypes.hxx> #include <wrtsh.hxx> -#include <uinums.hxx> #include <poolfmt.hxx> #include <charfmt.hxx> -#include <frmatr.hxx> #include <unomid.h> using namespace ::com::sun::star; -#define VERSION_30B ((sal_uInt16)250) -#define VERSION_31B ((sal_uInt16)326) -#define VERSION_40A ((sal_uInt16)364) -#define VERSION_53A ((sal_uInt16)596) -#define ACT_NUM_VERSION VERSION_53A - #define CHAPTER_FILENAME "chapter.cfg" /* @@ -57,7 +48,6 @@ using namespace ::com::sun::star; SwChapterNumRules::SwChapterNumRules() : sFileName(OUString(CHAPTER_FILENAME)) , - nVersion(0), bModified( false ) { Init(); @@ -125,55 +115,6 @@ void SwChapterNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, sal_uInt1 Save(); // store it immediately } -bool SwChapterNumRules::Store(SvStream &rStream) -{ - rStream.WriteUInt16( ACT_NUM_VERSION ); - // Write, what positions are occupied by a rule - // Then write each of the rules - for(sal_uInt16 i = 0; i < nMaxRules; ++i) - { - if(pNumRules[i]) - { - rStream.WriteUChar( sal_True ); - pNumRules[i]->Store( rStream ); - } - else - rStream.WriteUChar( sal_False ); - } - return true; -} - -int SwChapterNumRules::Load(SvStream &rStream) -{ - int rc = 0; - - rStream.ReadUInt16( nVersion ); - - // due to a small but serious mistake, PreFinal writes the same VERION_40A as SP2 - // #55402# - if(VERSION_40A == nVersion) - { - OSL_FAIL("Version 364 is not clear #55402#"); - } - else if( VERSION_30B == nVersion || VERSION_31B == nVersion || - ACT_NUM_VERSION >= nVersion ) - { - unsigned char bRule = sal_False; - for(sal_uInt16 i = 0; i < nMaxRules; ++i) - { - rStream.ReadUChar( bRule ); - if(bRule) - pNumRules[i] = new SwNumRulesWithName( rStream, nVersion ); - } - } - else - { - rc = 1; - } - - return rc; -} - SwNumRulesWithName::SwNumRulesWithName( const SwNumRule &rCopy, const OUString &rName ) : maName(rName) @@ -224,30 +165,6 @@ const SwNumRulesWithName& SwNumRulesWithName::operator=(const SwNumRulesWithName return *this; } -SwNumRulesWithName::SwNumRulesWithName( SvStream &rStream, sal_uInt16 nVersion ) -{ - rtl_TextEncoding eEncoding = osl_getThreadTextEncoding(); - maName = rStream.ReadUniOrByteString(eEncoding); - - char c; - for(sal_uInt16 n = 0; n < MAXLEVEL; ++n ) - { - if( VERSION_30B == nVersion ) - c = 1; - // due to a small but serious mistake, PreFinal writes the same VERION_40A as SP2 - // #55402# - else if(nVersion < VERSION_40A && n > 5) - c = 0; - else - rStream.ReadChar( c ); - - if( c ) - aFmts[ n ] = new _SwNumFmtGlobal( rStream, nVersion ); - else - aFmts[ n ] = 0; - } -} - void SwNumRulesWithName::MakeNumRule( SwWrtShell& rSh, SwNumRule& rChg ) const { // #i89178# @@ -263,24 +180,6 @@ void SwNumRulesWithName::MakeNumRule( SwWrtShell& rSh, SwNumRule& rChg ) const } } -void SwNumRulesWithName::Store( SvStream &rStream ) -{ - rtl_TextEncoding eEncoding = osl_getThreadTextEncoding(); - rStream.WriteUniOrByteString(maName, eEncoding); - - for( sal_uInt16 n = 0; n < MAXLEVEL; ++n ) - { - _SwNumFmtGlobal* pFmt = aFmts[ n ]; - if( pFmt ) - { - rStream.WriteChar( (char)1 ); - pFmt->Store( rStream ); - } - else - rStream.WriteChar( (char)0 ); - } -} - void SwNumRulesWithName::GetNumFmt( size_t const nIndex, SwNumFmt const*& rpNumFmt, OUString const*& rpName) const { @@ -335,222 +234,10 @@ SwNumRulesWithName::_SwNumFmtGlobal::_SwNumFmtGlobal( const _SwNumFmtGlobal& rFm aItems.push_back( rFmt.aItems[ --n ].Clone() ); } -SwNumRulesWithName::_SwNumFmtGlobal::_SwNumFmtGlobal( SvStream& rStream, - sal_uInt16 nVersion ) - : nCharPoolId( USHRT_MAX ) -{ - rtl_TextEncoding eEncoding = osl_getThreadTextEncoding(); - { - sal_uInt16 nUS; - short nShort; - sal_Char cChar; - bool bFlag; - OUString sStr; - - rStream.ReadUInt16( nUS ); aFmt.SetNumberingType((sal_Int16)nUS ); - if( VERSION_53A > nVersion ) - { - rStream.ReadChar( cChar ); aFmt.SetBulletChar( cChar ); - } - else - { - rStream.ReadUInt16( nUS ); aFmt.SetBulletChar( nUS ); - } - - rStream.ReadCharAsBool( bFlag ); aFmt.SetIncludeUpperLevels( bFlag ); - - if( VERSION_30B == nVersion ) - { - sal_Int32 nL; - rStream.ReadChar( cChar ); aFmt.SetStart( (sal_uInt16)cChar ); - - sStr = rStream.ReadUniOrByteString(eEncoding); - aFmt.SetPrefix( sStr ); - sStr = rStream.ReadUniOrByteString(eEncoding); - aFmt.SetSuffix( sStr ); - rStream.ReadUInt16( nUS ); aFmt.SetNumAdjust( SvxAdjust( nUS ) ); - rStream.ReadInt32( nL ); aFmt.SetLSpace( lNumIndent ); - rStream.ReadInt32( nL ); aFmt.SetFirstLineOffset( (short)nL ); - } - else // old start-value was a Byte - { - rStream.ReadUInt16( nUS ); aFmt.SetStart( nUS ); - sStr = rStream.ReadUniOrByteString(eEncoding); - aFmt.SetPrefix( sStr ); - sStr = rStream.ReadUniOrByteString(eEncoding); - aFmt.SetSuffix( sStr ); - rStream.ReadUInt16( nUS ); aFmt.SetNumAdjust( SvxAdjust( nUS ) ); - rStream.ReadUInt16( nUS ); aFmt.SetAbsLSpace( nUS ); - rStream.ReadInt16( nShort ); aFmt.SetFirstLineOffset( nShort ); - rStream.ReadUInt16( nUS ); aFmt.SetCharTextDistance( nUS ); - rStream.ReadInt16( nShort ); aFmt.SetLSpace( nShort ); - rStream.ReadCharAsBool( bFlag ); - } - - sal_uInt16 nFamily; - sal_uInt16 nCharSet; - short nWidth; - short nHeight; - sal_uInt16 nPitch; - OUString aName; - - aName = rStream.ReadUniOrByteString(eEncoding); - rStream.ReadUInt16( nFamily ).ReadUInt16( nCharSet ).ReadInt16( nWidth ).ReadInt16( nHeight ).ReadUInt16( nPitch ); - - if( !aName.isEmpty() ) - { - vcl::Font aFont( static_cast<FontFamily>(nFamily), Size( nWidth, nHeight ) ); - aFont.SetName( aName ); - aFont.SetCharSet( (rtl_TextEncoding)nCharSet ); - aFont.SetPitch( (FontPitch)nPitch ); - - aFmt.SetBulletFont( &aFont ); - } - else - nCharSet = RTL_TEXTENCODING_SYMBOL; - - if( VERSION_53A > nVersion ) - { - sal_Char cEncoded(aFmt.GetBulletChar()); - aFmt.SetBulletChar(OUString(&cEncoded, 1, nCharSet).toChar()); - } - } - - if( VERSION_30B != nVersion ) - { - sal_uInt16 nItemCount; - rStream.ReadUInt16( nCharPoolId ); - sCharFmtName = rStream.ReadUniOrByteString(eEncoding); - rStream.ReadUInt16( nItemCount ); - - while( nItemCount-- ) - { - sal_uInt16 nWhich, nVers; - rStream.ReadUInt16( nWhich ).ReadUInt16( nVers ); - if ( ( nWhich >= POOLATTR_BEGIN ) && ( nWhich < POOLATTR_END ) ) - aItems.push_back( GetDfltAttr( nWhich )->Create( rStream, nVers ) ); - } - } - - if( VERSION_40A == nVersion && SVX_NUM_BITMAP == aFmt.GetNumberingType() ) - { - sal_uInt8 cF; - sal_Int32 nWidth(0), nHeight(0); - - rStream.ReadInt32( nWidth ).ReadInt32( nHeight ); - - Size aSz(nWidth, nHeight); - - rStream.ReadUChar( cF ); - if( cF ) - { - SvxBrushItem* pBrush = 0; - SwFmtVertOrient* pVOrient = 0; - sal_uInt16 nVer; - - if( cF & 1 ) - { - rStream.ReadUInt16( nVer ); - pBrush = (SvxBrushItem*)GetDfltAttr( RES_BACKGROUND ) - ->Create( rStream, nVer ); - } - - if( cF & 2 ) - { - rStream.ReadUInt16( nVer ); - pVOrient = (SwFmtVertOrient*)GetDfltAttr( RES_VERT_ORIENT ) - ->Create( rStream, nVer ); - } - sal_Int16 eOrient = text::VertOrientation::NONE; - if(pVOrient) - eOrient = (sal_Int16)pVOrient->GetVertOrient(); - aFmt.SetGraphicBrush( pBrush, &aSz, pVOrient ? &eOrient : 0 ); - } - } -} - SwNumRulesWithName::_SwNumFmtGlobal::~_SwNumFmtGlobal() { } -void SwNumRulesWithName::_SwNumFmtGlobal::Store( SvStream& rStream ) -{ - rtl_TextEncoding eEncoding = osl_getThreadTextEncoding(); - { - OUString aName; - sal_uInt16 nFamily = FAMILY_DONTKNOW, nCharSet = 0, nPitch = 0; - short nWidth = 0, nHeight = 0; - - const vcl::Font* pFnt = aFmt.GetBulletFont(); - if( pFnt ) - { - aName = pFnt->GetName(); - nFamily = (sal_uInt16)pFnt->GetFamily(); - nCharSet = (sal_uInt16)pFnt->GetCharSet(); - nWidth = (short)pFnt->GetSize().Width(); - nHeight = (short)pFnt->GetSize().Height(); - nPitch = (sal_uInt16)pFnt->GetPitch(); - } - - rStream.WriteUInt16( aFmt.GetNumberingType() ) - .WriteUInt16( aFmt.GetBulletChar() ) - .WriteUChar( aFmt.GetIncludeUpperLevels() > 0 ) - .WriteUInt16( aFmt.GetStart() ); - rStream.WriteUniOrByteString( aFmt.GetPrefix(), eEncoding ); - rStream.WriteUniOrByteString( aFmt.GetSuffix(), eEncoding ); - rStream.WriteUInt16( aFmt.GetNumAdjust() ) - .WriteInt16( aFmt.GetAbsLSpace() ) - .WriteInt16( aFmt.GetFirstLineOffset() ) - .WriteInt16( aFmt.GetCharTextDistance() ) - .WriteInt16( aFmt.GetLSpace() ) - .WriteUChar( sal_False );//aFmt.IsRelLSpace(); - rStream.WriteUniOrByteString( aName, eEncoding ); - rStream.WriteUInt16( nFamily ) - .WriteUInt16( nCharSet ) - .WriteInt16( nWidth ) - .WriteInt16( nHeight ) - .WriteUInt16( nPitch ); - } - rStream.WriteUInt16( nCharPoolId ); - rStream.WriteUniOrByteString( sCharFmtName, eEncoding ); - rStream.WriteUInt16( aItems.size() ); - - for( sal_uInt16 n = aItems.size(); n; ) - { - SfxPoolItem* pItem = &aItems[ --n ]; - sal_uInt16 nIVers = pItem->GetVersion( SOFFICE_FILEFORMAT_50 ); - OSL_ENSURE( nIVers != USHRT_MAX, - "Was'n das: Item-Version USHRT_MAX in der aktuellen Version" ); - rStream.WriteUInt16( pItem->Which() ) - .WriteUInt16( nIVers ); - pItem->Store( rStream, nIVers ); - } - - // Extensions for 40A - - if( SVX_NUM_BITMAP == aFmt.GetNumberingType() ) - { - rStream.WriteInt32( aFmt.GetGraphicSize().Width() ) - .WriteInt32( aFmt.GetGraphicSize().Height() ); - sal_uInt8 cFlg = ( 0 != aFmt.GetBrush() ? 1 : 0 ) + - ( 0 != aFmt.GetGraphicOrientation() ? 2 : 0 ); - rStream.WriteUChar( cFlg ); - - if( aFmt.GetBrush() ) - { - sal_uInt16 nVersion = aFmt.GetBrush()->GetVersion( SOFFICE_FILEFORMAT_50 ); - rStream.WriteUInt16( nVersion ); - aFmt.GetBrush()->Store( rStream, nVersion ); - } - if( aFmt.GetGraphicOrientation() ) - { - sal_uInt16 nVersion = aFmt.GetGraphicOrientation()->GetVersion( SOFFICE_FILEFORMAT_50 ); - rStream.WriteUInt16( nVersion ); - aFmt.GetGraphicOrientation()->Store( rStream, nVersion ); - } - } -} - void SwNumRulesWithName::_SwNumFmtGlobal::ChgNumFmt( SwWrtShell& rSh, SwNumFmt& rNew ) const { diff --git a/sw/source/uibase/inc/uinums.hxx b/sw/source/uibase/inc/uinums.hxx index b593c1b..d01edec9 100644 --- a/sw/source/uibase/inc/uinums.hxx +++ b/sw/source/uibase/inc/uinums.hxx @@ -51,10 +51,8 @@ class SW_DLLPUBLIC SwNumRulesWithName public: _SwNumFmtGlobal( const SwNumFmt& rFmt ); _SwNumFmtGlobal( const _SwNumFmtGlobal& ); - _SwNumFmtGlobal( SvStream&, sal_uInt16 nVersion ); ~_SwNumFmtGlobal(); - void Store( SvStream& ); void ChgNumFmt( SwWrtShell& rSh, SwNumFmt& rChg ) const; }; @@ -70,7 +68,6 @@ protected: public: SwNumRulesWithName(const SwNumRule &, const OUString &); SwNumRulesWithName( const SwNumRulesWithName & ); - SwNumRulesWithName(SvStream &, sal_uInt16 nVersion); ~SwNumRulesWithName(); const SwNumRulesWithName &operator=(const SwNumRulesWithName &); @@ -78,7 +75,6 @@ public: const OUString& GetName() const { return maName; } void MakeNumRule( SwWrtShell& rSh, SwNumRule& rChg ) const; - void Store( SvStream& ); void GetNumFmt(size_t, SwNumFmt const*&, OUString const*&) const; }; @@ -90,12 +86,8 @@ public: protected: SwNumRulesWithName *pNumRules[ MAX_NUM_RULES ]; OUString sFileName; - sal_uInt16 nVersion; bool bModified; - virtual int Load(SvStream&); - virtual bool Store(SvStream&); - void Init(); void Save(); commit 79416bdbeded822bf39ac017b5816fa9aa8b359e Author: Michael Stahl <mst...@redhat.com> Date: Sat Nov 8 22:11:40 2014 +0100 sw: fix un-safe casts in SwXNumberingRules At least they check that the pointer they reinterpret-cast without checking the type isn't null! Change-Id: I07770e274598b1c476b4c297ac1d388b7ca576e5 diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx index bd89582..c9b4293 100644 --- a/sw/source/core/unocore/unosett.cxx +++ b/sw/source/core/unocore/unosett.cxx @@ -1938,15 +1938,15 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 17: //UNO_NAME_BULLET_FONT, { assert( !pDocShell ); - awt::FontDescriptor* pDesc = (awt::FontDescriptor*)pProp->Value.getValue(); - if(pDesc) + awt::FontDescriptor desc; + if (pProp->Value >>= desc) { // #i93725# // do not accept "empty" font - if ( !pDesc->Name.isEmpty() ) + if (!desc.Name.isEmpty()) { vcl::Font aFont; - SvxUnoFontDescriptor::ConvertToFont( *pDesc, aFont ); + SvxUnoFontDescriptor::ConvertToFont(desc, aFont); aFmt.SetBulletFont(&aFont); } } @@ -2016,8 +2016,8 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 21: //UNO_NAME_GRAPHIC_BITMAP, { assert( !pDocShell ); - uno::Reference< awt::XBitmap >* pBitmap = (uno::Reference< awt::XBitmap > *)pProp->Value.getValue(); - if(pBitmap) + uno::Reference<awt::XBitmap> xBitmap; + if (pProp->Value >>= xBitmap) { if(!pSetBrush) { @@ -2030,7 +2030,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( pSetBrush = new SvxBrushItem(OUString(), OUString(), GPOS_AREA, RES_BACKGROUND); } - BitmapEx aBmp = VCLUnoHelper::GetBitmap( *pBitmap ); + BitmapEx aBmp = VCLUnoHelper::GetBitmap(xBitmap); Graphic aNewGr(aBmp); pSetBrush->SetGraphic( aNewGr ); } @@ -2043,13 +2043,13 @@ void SwXNumberingRules::SetPropertiesToNumFmt( assert( !pDocShell ); if(!pSetSize) pSetSize = new Size; - if(pProp->Value.getValueType() == ::cppu::UnoType<awt::Size>::get()) + awt::Size size; + if (pProp->Value >>= size) { - awt::Size* pSize = (awt::Size*)pProp->Value.getValue(); - pSize->Width = convertMm100ToTwip(pSize->Width); - pSize->Height = convertMm100ToTwip(pSize->Height); - pSetSize->Width() = pSize->Width; - pSetSize->Height() = pSize->Height; + size.Width = convertMm100ToTwip(size.Width); + size.Height = convertMm100ToTwip(size.Height); + pSetSize->Width() = size.Width; + pSetSize->Height() = size.Height; } else bWrongArg = true; commit 7bbda9b227c372898a80f75655a67eee0bdfabf3 Author: Michael Stahl <mst...@redhat.com> Date: Sat Nov 8 21:56:09 2014 +0100 sw: remove the PropValData abomination Conciseness and type safety: why try to achieve both when you can settle for neither. Change-Id: I68399395083e3ad927c544700cb37363856b1788 diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx index 687f027..bd89582 100644 --- a/sw/source/core/unocore/unosett.cxx +++ b/sw/source/core/unocore/unosett.cxx @@ -64,6 +64,7 @@ #include <com/sun/star/text/PositionAndSpaceMode.hpp> #include <com/sun/star/text/LabelFollow.hpp> #include <numrule.hxx> +#include <comphelper/sequenceasvector.hxx> #include <comphelper/servicehelper.hxx> #include <cppuhelper/supportsservice.hxx> #include <paratr.hxx> @@ -75,19 +76,11 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star::text; using namespace ::com::sun::star::style; -struct PropValData -{ - uno::Any aVal; - OUString sPropName; - PropValData(void* pVal, const char* cPropName, uno::Type aType ) : - aVal(pVal, aType), - sPropName(OUString::createFromAscii(cPropName)) - {} - PropValData(const uno::Any& rVal, const OUString& rPropName) : - aVal(rVal), - sPropName(rPropName) - {} -}; +template<typename T> +PropertyValue makePropertyValue(T const& rValue, OUString const& rName) +{ + return PropertyValue(rName, -1, makeAny(rValue), PropertyState_DIRECT_VALUE); +} // Constants for the css::text::ColumnSeparatorStyle #define API_COL_LINE_NONE 0 @@ -95,8 +88,6 @@ struct PropValData #define API_COL_LINE_DOTTED 2 #define API_COL_LINE_DASHED 3 -typedef std::vector<PropValData*> PropValDataArr; - #define WID_PREFIX 0 #define WID_SUFFIX 1 #define WID_NUMBERING_TYPE 2 @@ -1384,59 +1375,54 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( { bool bChapterNum = pHeadingStyleName != 0; - PropValDataArr aPropertyValues; + ::comphelper::SequenceAsVector<PropertyValue> aPropertyValues; + aPropertyValues.reserve(32); //fill all properties into the array //adjust SvxAdjust eAdj = rFmt.GetNumAdjust(); sal_Int16 nINT16 = aSvxToUnoAdjust[eAdj]; - PropValData* pData = new PropValData((void*)&nINT16, "Adjust", ::cppu::UnoType<sal_Int16>::get() ); - aPropertyValues.push_back(pData); + aPropertyValues.push_back(makePropertyValue(nINT16, "Adjust")); //parentnumbering nINT16 = rFmt.GetIncludeUpperLevels(); - pData = new PropValData((void*)&nINT16, "ParentNumbering", ::cppu::UnoType<sal_Int16>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back(makePropertyValue(nINT16, "ParentNumbering")); //prefix OUString aUString = rFmt.GetPrefix(); - pData = new PropValData((void*)&aUString, "Prefix", ::cppu::UnoType<OUString>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back(makePropertyValue(aUString, "Prefix")); //suffix aUString = rFmt.GetSuffix(); - pData = new PropValData((void*)&aUString, "Suffix", ::cppu::UnoType<OUString>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back(makePropertyValue(aUString, "Suffix")); //char style name OUString CharStyleName(rCharFormatName); aUString = OUString(); SwStyleNameMapper::FillProgName( CharStyleName, aUString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true ); - pData = new PropValData((void*)&aUString, "CharStyleName", ::cppu::UnoType<OUString>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back(makePropertyValue(aUString, "CharStyleName")); //startvalue nINT16 = rFmt.GetStart(); - pData = new PropValData((void*)&nINT16, "StartWith", ::cppu::UnoType<sal_Int16>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back(makePropertyValue(nINT16, "StartWith")); if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION ) { //leftmargin sal_Int32 nINT32 = convertTwipToMm100(rFmt.GetAbsLSpace()); - pData = new PropValData((void*)&nINT32, UNO_NAME_LEFT_MARGIN, ::cppu::UnoType<sal_Int32>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(nINT32, UNO_NAME_LEFT_MARGIN)); //chartextoffset nINT32 = convertTwipToMm100(rFmt.GetCharTextDistance()); - pData = new PropValData((void*)&nINT32, UNO_NAME_SYMBOL_TEXT_DISTANCE, ::cppu::UnoType<sal_Int32>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(nINT32, UNO_NAME_SYMBOL_TEXT_DISTANCE)); //firstlineoffset nINT32 = convertTwipToMm100(rFmt.GetFirstLineOffset()); - pData = new PropValData((void*)&nINT32, UNO_NAME_FIRST_LINE_OFFSET, ::cppu::UnoType<sal_Int32>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(nINT32, UNO_NAME_FIRST_LINE_OFFSET)); } // PositionAndSpaceMode @@ -1445,10 +1431,8 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( { nINT16 = PositionAndSpaceMode::LABEL_ALIGNMENT; } - pData = new PropValData( (void*)&nINT16, - UNO_NAME_POSITION_AND_SPACE_MODE, - ::cppu::UnoType<sal_Int16>::get() ); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(nINT16, UNO_NAME_POSITION_AND_SPACE_MODE)); if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT ) { @@ -1462,37 +1446,28 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( { nINT16 = LabelFollow::NOTHING; } - pData = new PropValData( (void*)&nINT16, - UNO_NAME_LABEL_FOLLOWED_BY, - ::cppu::UnoType<sal_Int16>::get() ); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(nINT16, UNO_NAME_LABEL_FOLLOWED_BY)); // ListtabStopPosition sal_Int32 nINT32 = convertTwipToMm100(rFmt.GetListtabPos()); - pData = new PropValData( (void*)&nINT32, - UNO_NAME_LISTTAB_STOP_POSITION, - ::cppu::UnoType<sal_Int32>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(nINT32, UNO_NAME_LISTTAB_STOP_POSITION)); // FirstLineIndent nINT32 = convertTwipToMm100(rFmt.GetFirstLineIndent()); - pData = new PropValData( (void*)&nINT32, - UNO_NAME_FIRST_LINE_INDENT, - ::cppu::UnoType<sal_Int32>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(nINT32, UNO_NAME_FIRST_LINE_INDENT)); // IndentAt nINT32 = convertTwipToMm100(rFmt.GetIndentAt()); - pData = new PropValData( (void*)&nINT32, - UNO_NAME_INDENT_AT, - ::cppu::UnoType<sal_Int32>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(nINT32, UNO_NAME_INDENT_AT)); } //numberingtype nINT16 = rFmt.GetNumberingType(); - pData = new PropValData((void*)&nINT16, "NumberingType", ::cppu::UnoType<sal_Int16>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back(makePropertyValue(nINT16, "NumberingType")); if(!bChapterNum) { @@ -1500,28 +1475,25 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( { //BulletId nINT16 = rFmt.GetBulletChar(); - pData = new PropValData((void*)&nINT16, "BulletId", ::cppu::UnoType<sal_Int16>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back(makePropertyValue(nINT16, "BulletId")); const vcl::Font* pFont = rFmt.GetBulletFont(); //BulletChar aUString = OUString(rFmt.GetBulletChar()); - pData = new PropValData((void*)&aUString, "BulletChar", ::cppu::UnoType<OUString>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back(makePropertyValue(aUString, "BulletChar")); //BulletFontName aUString = pFont ? pFont->GetStyleName() : OUString(); - pData = new PropValData((void*)&aUString, "BulletFontName", ::cppu::UnoType<OUString>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back(makePropertyValue(aUString, "BulletFontName")); //BulletFont if(pFont) { awt::FontDescriptor aDesc; SvxUnoFontDescriptor::ConvertFromFont( *pFont, aDesc ); - pData = new PropValData((void*)&aDesc, UNO_NAME_BULLET_FONT, cppu::UnoType<awt::FontDescriptor>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(aDesc, UNO_NAME_BULLET_FONT)); } } if(SVX_NUM_BITMAP == rFmt.GetNumberingType()) @@ -1536,8 +1508,8 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( } else aUString = OUString(); - pData = new PropValData((void*)&aUString, UNO_NAME_GRAPHIC_URL, ::cppu::UnoType<OUString>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(aUString, UNO_NAME_GRAPHIC_URL)); //graphicbitmap const Graphic* pGraphic = 0; @@ -1546,56 +1518,44 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( if(pGraphic) { uno::Reference<awt::XBitmap> xBmp = VCLUnoHelper::CreateBitmap( pGraphic->GetBitmapEx() ); - pData = new PropValData((void*)&xBmp, UNO_NAME_GRAPHIC_BITMAP, - cppu::UnoType<awt::XBitmap>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(xBmp, UNO_NAME_GRAPHIC_BITMAP)); } Size aSize = rFmt.GetGraphicSize(); // #i101131# // adjust conversion due to type mismatch between <Size> and <awt::Size> awt::Size aAwtSize(convertTwipToMm100(aSize.Width()), convertTwipToMm100(aSize.Height())); - pData = new PropValData((void*)&aAwtSize, UNO_NAME_GRAPHIC_SIZE, ::cppu::UnoType<awt::Size>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(aAwtSize, UNO_NAME_GRAPHIC_SIZE)); const SwFmtVertOrient* pOrient = rFmt.GetGraphicOrientation(); if(pOrient) { - pData = new PropValData((void*)0, UNO_NAME_VERT_ORIENT, ::cppu::UnoType<sal_Int16>::get()); - ((const SfxPoolItem*)pOrient)->QueryValue(pData->aVal, MID_VERTORIENT_ORIENT); - aPropertyValues.push_back(pData); + uno::Any any; + pOrient->QueryValue(any, MID_VERTORIENT_ORIENT); + aPropertyValues.push_back(PropertyValue( + UNO_NAME_VERT_ORIENT, -1, any, PropertyState_DIRECT_VALUE)); } } } else { aUString = *pHeadingStyleName; - pData = new PropValData((void*)&aUString, UNO_NAME_HEADING_STYLE_NAME, ::cppu::UnoType<OUString>::get()); - aPropertyValues.push_back(pData); + aPropertyValues.push_back( + makePropertyValue(aUString, UNO_NAME_HEADING_STYLE_NAME)); } - uno::Sequence<beans::PropertyValue> aSeq(aPropertyValues.size()); - beans::PropertyValue* pArray = aSeq.getArray(); - - for(size_t i = 0; i < aPropertyValues.size(); ++i) - { - pData = aPropertyValues[i]; - pArray[i].Value = pData->aVal; - pArray[i].Name = pData->sPropName; - pArray[i].Handle = -1; - } - for (PropValDataArr::const_iterator it = aPropertyValues.begin(); it != aPropertyValues.end(); ++it) - delete *it; - aPropertyValues.clear(); - return aSeq; + return aPropertyValues.getAsConstList(); } -static PropValData* lcl_FindProperty(const char* cName, PropValDataArr& rPropertyValues) +static PropertyValue const* lcl_FindProperty( + const char* cName, std::vector<PropertyValue const*> const& rPropertyValues) { const OUString sCmp = OUString::createFromAscii(cName); for(size_t i = 0; i < rPropertyValues.size(); ++i) { - PropValData* pTemp = rPropertyValues[i]; - if(sCmp == pTemp->sPropName) + PropertyValue const*const pTemp = rPropertyValues[i]; + if (sCmp == pTemp->Name) return pTemp; } return 0; @@ -1709,7 +1669,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( }; const beans::PropertyValue* pPropArray = rProperties.getConstArray(); - PropValDataArr aPropertyValues; + ::std::vector<PropertyValue const*> aPropertyValues; bool bExcept = false; for(sal_Int32 i = 0; i < rProperties.getLength() && !bExcept; i++) { @@ -1732,8 +1692,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( } } SAL_WARN_IF( bExcept, "sw.uno", "Unknown/incorrect property " << rProp.Name << ", failing" ); - PropValData* pData = new PropValData(rProp.Value, rProp.Name ); - aPropertyValues.push_back(pData); + aPropertyValues.push_back(& rProp); } bool bWrongArg = false; @@ -1746,15 +1705,16 @@ void SwXNumberingRules::SetPropertiesToNumFmt( for(size_t i = 0; i < SAL_N_ELEMENTS( aNumPropertyNames ) && !bExcept && !bWrongArg; ++i) { - PropValData* pData = lcl_FindProperty(aNumPropertyNames[i], aPropertyValues); - if(!pData) + PropertyValue const*const pProp( + lcl_FindProperty(aNumPropertyNames[i], aPropertyValues)); + if (!pProp) continue; switch(i) { case 0: //"Adjust" { sal_Int16 nValue = 0; - pData->aVal >>= nValue; + pProp->Value >>= nValue; if(nValue > 0 && nValue <= text::HoriOrientation::LEFT && USHRT_MAX != aUnoToSvxAdjust[nValue]) @@ -1768,7 +1728,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 1: //"ParentNumbering", { sal_Int16 nSet = 0; - pData->aVal >>= nSet; + pProp->Value >>= nSet; if(nSet >= 0 && MAXLEVEL >= nSet) aFmt.SetIncludeUpperLevels( static_cast< sal_uInt8 >(nSet) ); } @@ -1776,14 +1736,14 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 2: //"Prefix", { OUString uTmp; - pData->aVal >>= uTmp; + pProp->Value >>= uTmp; aFmt.SetPrefix(uTmp); } break; case 3: //"Suffix", { OUString uTmp; - pData->aVal >>= uTmp; + pProp->Value >>= uTmp; aFmt.SetSuffix(uTmp); } break; @@ -1791,7 +1751,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( { bCharStyleNameSet = true; OUString uTmp; - pData->aVal >>= uTmp; + pProp->Value >>= uTmp; OUString sCharFmtName; SwStyleNameMapper::FillUIName( uTmp, sCharFmtName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true ); if (sCharFmtName == UNO_NAME_CHARACTER_FORMAT_NONE) @@ -1841,14 +1801,14 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 5: //"StartWith", { sal_Int16 nVal = 0; - pData->aVal >>= nVal; + pProp->Value >>= nVal; aFmt.SetStart(nVal); } break; case 6: //UNO_NAME_LEFT_MARGIN, { sal_Int32 nValue = 0; - pData->aVal >>= nValue; + pProp->Value >>= nValue; // #i23727# nValue can be negative aFmt.SetAbsLSpace((short) convertMm100ToTwip(nValue)); } @@ -1856,7 +1816,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 7: //UNO_NAME_SYMBOL_TEXT_DISTANCE, { sal_Int32 nValue = 0; - pData->aVal >>= nValue; + pProp->Value >>= nValue; if(nValue >= 0) aFmt.SetCharTextDistance((short) convertMm100ToTwip(nValue)); else @@ -1866,7 +1826,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 8: //UNO_NAME_FIRST_LINE_OFFSET, { sal_Int32 nValue = 0; - pData->aVal >>= nValue; + pProp->Value >>= nValue; // #i23727# nValue can be positive nValue = convertMm100ToTwip(nValue); aFmt.SetFirstLineOffset((short)nValue); @@ -1875,7 +1835,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 9: // UNO_NAME_POSITION_AND_SPACE_MODE { sal_Int16 nValue = 0; - pData->aVal >>= nValue; + pProp->Value >>= nValue; if ( nValue == 0 ) { aFmt.SetPositionAndSpaceMode( SvxNumberFormat::LABEL_WIDTH_AND_POSITION ); @@ -1893,7 +1853,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 10: // UNO_NAME_LABEL_FOLLOWED_BY { sal_Int16 nValue = 0; - pData->aVal >>= nValue; + pProp->Value >>= nValue; if ( nValue == 0 ) { aFmt.SetLabelFollowedBy( SvxNumberFormat::LISTTAB ); @@ -1915,7 +1875,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 11: // UNO_NAME_LISTTAB_STOP_POSITION { sal_Int32 nValue = 0; - pData->aVal >>= nValue; + pProp->Value >>= nValue; nValue = convertMm100ToTwip(nValue); if ( nValue >= 0 ) { @@ -1930,7 +1890,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 12: // UNO_NAME_FIRST_LINE_INDENT { sal_Int32 nValue = 0; - pData->aVal >>= nValue; + pProp->Value >>= nValue; nValue = convertMm100ToTwip(nValue); aFmt.SetFirstLineIndent( nValue ); } @@ -1938,7 +1898,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 13: // UNO_NAME_INDENT_AT { sal_Int32 nValue = 0; - pData->aVal >>= nValue; + pProp->Value >>= nValue; nValue = convertMm100ToTwip(nValue); aFmt.SetIndentAt( nValue ); } @@ -1946,7 +1906,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 14: //"NumberingType" { sal_Int16 nSet = 0; - pData->aVal >>= nSet; + pProp->Value >>= nSet; if(nSet >= 0) aFmt.SetNumberingType(nSet); else @@ -1958,7 +1918,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( if (pParagraphStyleName) { OUString uTmp; - pData->aVal >>= uTmp; + pProp->Value >>= uTmp; OUString sStyleName; SwStyleNameMapper::FillUIName(uTmp, sStyleName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true ); *pParagraphStyleName = sStyleName; @@ -1969,7 +1929,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( { assert( !pDocShell ); sal_Int16 nSet = 0; - if( pData->aVal >>= nSet ) + if( pProp->Value >>= nSet ) aFmt.SetBulletChar(nSet); else bWrongArg = true; @@ -1978,7 +1938,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( case 17: //UNO_NAME_BULLET_FONT, { assert( !pDocShell ); - awt::FontDescriptor* pDesc = (awt::FontDescriptor*)pData->aVal.getValue(); + awt::FontDescriptor* pDesc = (awt::FontDescriptor*)pProp->Value.getValue(); if(pDesc) { // #i93725# @@ -1998,7 +1958,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( { assert( !pDocShell ); OUString sBulletFontName; - pData->aVal >>= sBulletFontName; + pProp->Value >>= sBulletFontName; SwDocShell* pLclDocShell = pDocShell ? pDocShell : pDoc ? pDoc->GetDocShell() : 0; if( !sBulletFontName.isEmpty() && pLclDocShell ) { @@ -2019,7 +1979,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( { assert( !pDocShell ); OUString aChar; - pData->aVal >>= aChar; + pProp->Value >>= aChar; if(aChar.getLength() == 1) { aFmt.SetBulletChar(aChar.toChar()); @@ -2039,7 +1999,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( { assert( !pDocShell ); OUString sBrushURL; - pData->aVal >>= sBrushURL; + pProp->Value >>= sBrushURL; if(!pSetBrush) { const SvxBrushItem* pOrigBrush = aFmt.GetBrush(); @@ -2050,13 +2010,13 @@ void SwXNumberingRules::SetPropertiesToNumFmt( else pSetBrush = new SvxBrushItem(OUString(), OUString(), GPOS_AREA, RES_BACKGROUND); } - pSetBrush->PutValue( pData->aVal, MID_GRAPHIC_URL ); + pSetBrush->PutValue( pProp->Value, MID_GRAPHIC_URL ); } break; case 21: //UNO_NAME_GRAPHIC_BITMAP, { assert( !pDocShell ); - uno::Reference< awt::XBitmap >* pBitmap = (uno::Reference< awt::XBitmap > *)pData->aVal.getValue(); + uno::Reference< awt::XBitmap >* pBitmap = (uno::Reference< awt::XBitmap > *)pProp->Value.getValue(); if(pBitmap) { if(!pSetBrush) @@ -2083,9 +2043,9 @@ void SwXNumberingRules::SetPropertiesToNumFmt( assert( !pDocShell ); if(!pSetSize) pSetSize = new Size; - if(pData->aVal.getValueType() == ::cppu::UnoType<awt::Size>::get()) + if(pProp->Value.getValueType() == ::cppu::UnoType<awt::Size>::get()) { - awt::Size* pSize = (awt::Size*)pData->aVal.getValue(); + awt::Size* pSize = (awt::Size*)pProp->Value.getValue(); pSize->Width = convertMm100ToTwip(pSize->Width); pSize->Height = convertMm100ToTwip(pSize->Height); pSetSize->Width() = pSize->Width; @@ -2105,7 +2065,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( else pSetVOrient = new SwFmtVertOrient; } - ((SfxPoolItem*)pSetVOrient)->PutValue(pData->aVal, MID_VERTORIENT_ORIENT); + pSetVOrient->PutValue(pProp->Value, MID_VERTORIENT_ORIENT); } break; case 24: //"HeadingStyleName" @@ -2113,7 +2073,7 @@ void SwXNumberingRules::SetPropertiesToNumFmt( if (pHeadingStyleName) { OUString uTmp; - pData->aVal >>= uTmp; + pProp->Value >>= uTmp; OUString sStyleName; SwStyleNameMapper::FillUIName(uTmp, sStyleName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true ); *pHeadingStyleName = sStyleName; @@ -2164,9 +2124,6 @@ void SwXNumberingRules::SetPropertiesToNumFmt( delete pSetSize; delete pSetVOrient; } - for (PropValDataArr::const_iterator it = aPropertyValues.begin(); it != aPropertyValues.end(); ++it) - delete *it; - aPropertyValues.clear(); if(bWrongArg) throw lang::IllegalArgumentException(); commit 526d6c96b6e39ed0a126ff6b64f125f082a8abbc Author: Michael Stahl <mst...@redhat.com> Date: Sat Nov 8 20:41:23 2014 +0100 sw: these can be asserts Change-Id: I4ad1ff6fad2f4097c128dcaea5cf6064e2524aad diff --git a/sw/source/uibase/config/uinums.cxx b/sw/source/uibase/config/uinums.cxx index 7ccb532..d0d872f 100644 --- a/sw/source/uibase/config/uinums.cxx +++ b/sw/source/uibase/config/uinums.cxx @@ -117,7 +117,7 @@ void SwChapterNumRules::CreateEmptyNumRule(sal_uInt16 const nIndex) void SwChapterNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, sal_uInt16 nIdx) { bModified = true; - OSL_ENSURE(nIdx < nMaxRules, "Array der NumRules ueberindiziert."); + assert(nIdx < nMaxRules); if( !pNumRules[nIdx] ) pNumRules[nIdx] = new SwNumRulesWithName( rCopy ); else diff --git a/sw/source/uibase/inc/uinums.hxx b/sw/source/uibase/inc/uinums.hxx index e95bc9c..b593c1b 100644 --- a/sw/source/uibase/inc/uinums.hxx +++ b/sw/source/uibase/inc/uinums.hxx @@ -113,7 +113,7 @@ public: inline const SwNumRulesWithName *SwChapterNumRules::GetRules(sal_uInt16 nIdx) const { - OSL_ENSURE(nIdx < nMaxRules, "Array der NumRules ueberindiziert."); + assert(nIdx < nMaxRules); return pNumRules[nIdx]; } commit e377a65a1e6acf6241ce0bd2fc35a6a786cd8de9 Author: Michael Stahl <mst...@redhat.com> Date: Sat Nov 8 20:40:19 2014 +0100 sw: remove pointless inheritance of SwChapterNumRules from SwBaseNumRules Change-Id: I5426977d4ed5539d79335df0aa4bcccd71dd8966 diff --git a/sw/source/ui/misc/outline.cxx b/sw/source/ui/misc/outline.cxx index c3eae29..d669783 100644 --- a/sw/source/ui/misc/outline.cxx +++ b/sw/source/ui/misc/outline.cxx @@ -91,13 +91,13 @@ IMPL_LINK_INLINE_END( SwNumNamesDlg, SelectHdl, ListBox *, pBox ) void SwNumNamesDlg::SetUserNames(const OUString *pList[]) { sal_uInt16 nSelect = 0; - for(sal_uInt16 i = 0; i < SwBaseNumRules::nMaxRules; ++i) + for (sal_uInt16 i = 0; i < SwChapterNumRules::nMaxRules; ++i) { if(pList[i]) { m_pFormBox->RemoveEntry(i); m_pFormBox->InsertEntry(*pList[i], i); - if(i == nSelect && nSelect < SwBaseNumRules::nMaxRules) + if (i == nSelect && nSelect < SwChapterNumRules::nMaxRules) nSelect++; } } diff --git a/sw/source/uibase/config/StoredChapterNumbering.cxx b/sw/source/uibase/config/StoredChapterNumbering.cxx index 245e884..eb8ae2f 100644 --- a/sw/source/uibase/config/StoredChapterNumbering.cxx +++ b/sw/source/uibase/config/StoredChapterNumbering.cxx @@ -46,7 +46,7 @@ class StoredChapterNumberingRules { private: // TODO in case this ever becomes accessible via api need a invalidate - SwBaseNumRules & m_rNumRules; + SwChapterNumRules & m_rNumRules; sal_uInt16 const m_nIndex; SwNumRulesWithName * GetOrCreateRules() @@ -63,11 +63,11 @@ private: public: StoredChapterNumberingRules( - SwBaseNumRules & rNumRules, sal_uInt16 const nIndex) + SwChapterNumRules & rNumRules, sal_uInt16 const nIndex) : m_rNumRules(rNumRules) , m_nIndex(nIndex) { - assert(m_nIndex < SwBaseNumRules::nMaxRules); + assert(m_nIndex < SwChapterNumRules::nMaxRules); } // XNamed @@ -324,13 +324,13 @@ class StoredChapterNumberingRootContext : public SvXMLImportContext { private: - SwBaseNumRules & m_rNumRules; + SwChapterNumRules & m_rNumRules; size_t m_nCounter; ::std::vector<tools::SvRef<SvxXMLListStyleContext>> m_Contexts; public: StoredChapterNumberingRootContext( - SwBaseNumRules & rNumRules, SvXMLImport & rImport, + SwChapterNumRules & rNumRules, SvXMLImport & rImport, sal_uInt16 const nPrefix, OUString const& rLocalName) : SvXMLImportContext(rImport, nPrefix, rLocalName) , m_rNumRules(rNumRules) @@ -340,7 +340,7 @@ public: virtual void EndElement() SAL_OVERRIDE { - assert(m_Contexts.size() < SwBaseNumRules::nMaxRules); + assert(m_Contexts.size() < SwChapterNumRules::nMaxRules); for (auto iter = m_Contexts.begin(); iter != m_Contexts.end(); ++iter) { uno::Reference<container::XIndexReplace> const xRule( @@ -360,7 +360,7 @@ public: if (XML_NAMESPACE_TEXT == nPrefix && IsXMLToken(rLocalName, XML_OUTLINE_STYLE)) { ++m_nCounter; - if (m_nCounter <= SwBaseNumRules::nMaxRules) + if (m_nCounter <= SwChapterNumRules::nMaxRules) { SvxXMLListStyleContext *const pContext( new SvxXMLListStyleContext(GetImport(), @@ -384,12 +384,12 @@ class StoredChapterNumberingImport : public SvXMLImport { private: - SwBaseNumRules & m_rNumRules; + SwChapterNumRules & m_rNumRules; public: StoredChapterNumberingImport( uno::Reference<uno::XComponentContext> const& xContext, - SwBaseNumRules & rNumRules) + SwChapterNumRules & rNumRules) : SvXMLImport(xContext, "sw::StoredChapterNumberingImport", IMPORT_ALL) , m_rNumRules(rNumRules) { @@ -408,7 +408,7 @@ public: } }; -void ExportStoredChapterNumberingRules(SwBaseNumRules & rRules, +void ExportStoredChapterNumberingRules(SwChapterNumRules & rRules, SvStream & rStream, OUString const& rFileName) { uno::Reference<uno::XComponentContext> const xContext( @@ -432,7 +432,7 @@ void ExportStoredChapterNumberingRules(SwBaseNumRules & rRules, // ... and the import needs to map from name to display-name then! std::set<OUString> charStyles; std::vector<uno::Reference<container::XIndexReplace>> numRules; - for (size_t i = 0; i < SwBaseNumRules::nMaxRules; ++i) + for (size_t i = 0; i < SwChapterNumRules::nMaxRules; ++i) { if (SwNumRulesWithName const* pRule = rRules.GetRules(i)) { @@ -461,7 +461,7 @@ void ExportStoredChapterNumberingRules(SwBaseNumRules & rRules, } } -void ImportStoredChapterNumberingRules(SwBaseNumRules & rRules, +void ImportStoredChapterNumberingRules(SwChapterNumRules & rRules, SvStream & rStream, OUString const& rFileName) { uno::Reference<uno::XComponentContext> const xContext( diff --git a/sw/source/uibase/config/uinums.cxx b/sw/source/uibase/config/uinums.cxx index 2d03704..7ccb532 100644 --- a/sw/source/uibase/config/uinums.cxx +++ b/sw/source/uibase/config/uinums.cxx @@ -54,16 +54,16 @@ using namespace ::com::sun::star; An old rule at that position will be overwritten. */ -SwBaseNumRules::SwBaseNumRules( const OUString& rFileName ) - : - sFileName( rFileName ), +SwChapterNumRules::SwChapterNumRules() + : sFileName(OUString(CHAPTER_FILENAME)) + , nVersion(0), bModified( false ) { Init(); } -void SwBaseNumRules::Save() +void SwChapterNumRules::Save() { if( bModified ) { @@ -87,13 +87,13 @@ void SwBaseNumRules::Save() } } -SwBaseNumRules::~SwBaseNumRules() +SwChapterNumRules::~SwChapterNumRules() { for( sal_uInt16 i = 0; i < nMaxRules; ++i ) delete pNumRules[i]; } -void SwBaseNumRules::Init() +void SwChapterNumRules::Init() { for(sal_uInt16 i = 0; i < nMaxRules; ++i ) pNumRules[i] = 0; @@ -107,15 +107,16 @@ void SwBaseNumRules::Init() } } -void SwBaseNumRules::CreateEmptyNumRule(sal_uInt16 const nIndex) +void SwChapterNumRules::CreateEmptyNumRule(sal_uInt16 const nIndex) { assert(nIndex < nMaxRules); assert(!pNumRules[nIndex]); pNumRules[nIndex] = new SwNumRulesWithName; } -void SwBaseNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, sal_uInt16 nIdx) +void SwChapterNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, sal_uInt16 nIdx) { + bModified = true; OSL_ENSURE(nIdx < nMaxRules, "Array der NumRules ueberindiziert."); if( !pNumRules[nIdx] ) pNumRules[nIdx] = new SwNumRulesWithName( rCopy ); @@ -124,7 +125,7 @@ void SwBaseNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, sal_uInt16 n Save(); // store it immediately } -bool SwBaseNumRules::Store(SvStream &rStream) +bool SwChapterNumRules::Store(SvStream &rStream) { rStream.WriteUInt16( ACT_NUM_VERSION ); // Write, what positions are occupied by a rule @@ -142,7 +143,7 @@ bool SwBaseNumRules::Store(SvStream &rStream) return true; } -int SwBaseNumRules::Load(SvStream &rStream) +int SwChapterNumRules::Load(SvStream &rStream) { int rc = 0; @@ -173,21 +174,6 @@ int SwBaseNumRules::Load(SvStream &rStream) return rc; } -SwChapterNumRules::SwChapterNumRules() : - SwBaseNumRules(OUString(CHAPTER_FILENAME)) -{ -} - - SwChapterNumRules::~SwChapterNumRules() -{ -} - -void SwChapterNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, sal_uInt16 nIdx) -{ - bModified = true; - SwBaseNumRules::ApplyNumRules(rCopy, nIdx); -} - SwNumRulesWithName::SwNumRulesWithName( const SwNumRule &rCopy, const OUString &rName ) : maName(rName) diff --git a/sw/source/uibase/inc/uinums.hxx b/sw/source/uibase/inc/uinums.hxx index bb1627e..e95bc9c 100644 --- a/sw/source/uibase/inc/uinums.hxx +++ b/sw/source/uibase/inc/uinums.hxx @@ -62,7 +62,7 @@ class SW_DLLPUBLIC SwNumRulesWithName protected: friend class sw::StoredChapterNumberingRules; - friend class SwBaseNumRules; + friend class SwChapterNumRules; void SetName(const OUString& rSet) {maName = rSet;} void SetNumFmt(size_t, SwNumFmt const&, OUString const&); SwNumRulesWithName(); @@ -83,7 +83,7 @@ public: void GetNumFmt(size_t, SwNumFmt const*&, OUString const*&) const; }; -class SwBaseNumRules +class SwChapterNumRules { public: enum { nMaxRules = MAX_NUM_RULES }; // currently 9 defined forms @@ -100,8 +100,8 @@ protected: void Save(); public: - SwBaseNumRules(const OUString& rFileName); - virtual ~SwBaseNumRules(); + SwChapterNumRules(); + virtual ~SwChapterNumRules(); inline const SwNumRulesWithName* GetRules(sal_uInt16 nIdx) const; void CreateEmptyNumRule(sal_uInt16 nIdx); // for import @@ -111,18 +111,7 @@ public: }; -class SwChapterNumRules : public SwBaseNumRules -{ - -public: - SwChapterNumRules(); - virtual ~SwChapterNumRules(); - - virtual void ApplyNumRules( const SwNumRulesWithName &rCopy, - sal_uInt16 nIdx) SAL_OVERRIDE; -}; - -inline const SwNumRulesWithName *SwBaseNumRules::GetRules(sal_uInt16 nIdx) const +inline const SwNumRulesWithName *SwChapterNumRules::GetRules(sal_uInt16 nIdx) const { OSL_ENSURE(nIdx < nMaxRules, "Array der NumRules ueberindiziert."); return pNumRules[nIdx]; @@ -133,9 +122,9 @@ namespace sw { void ExportStoredChapterNumberingRules( - SwBaseNumRules & rRules, SvStream & rStream, OUString const&); + SwChapterNumRules & rRules, SvStream & rStream, OUString const&); void ImportStoredChapterNumberingRules( - SwBaseNumRules & rRules, SvStream & rStream, OUString const&); + SwChapterNumRules & rRules, SvStream & rStream, OUString const&); } // namespace sw commit f7c14f57300255bb279ccd95d6b87347b1e0aec2 Author: Michael Stahl <mst...@redhat.com> Date: Sat Nov 8 20:27:51 2014 +0100 xmloff: remove unused parameter of SvxXMLListStyleContext::FillUnoNumRule() Change-Id: I359f37ce778d55e6868bd1c78c0ff0d452f36088 diff --git a/include/xmloff/xmlnumi.hxx b/include/xmloff/xmlnumi.hxx index 413b9ff..c4ef733 100644 --- a/include/xmloff/xmlnumi.hxx +++ b/include/xmloff/xmlnumi.hxx @@ -26,7 +26,7 @@ #include <com/sun/star/style/NumberingType.hpp> namespace com { namespace sun { namespace star { namespace frame { class XModel; } } } } -class SvI18NMap; + class SvxXMLListLevelStyleContext_Impl; typedef std::vector<SvxXMLListLevelStyleContext_Impl *> SvxXMLListStyle_Impl; @@ -72,9 +72,8 @@ public: ::com::sun::star::xml::sax::XAttributeList >& xAttrList ) SAL_OVERRIDE; void FillUnoNumRule( - const ::com::sun::star::uno::Reference< - ::com::sun::star::container::XIndexReplace > & rNumRule, - const SvI18NMap *pI18NMap ) const; + const css::uno::Reference< + css::container::XIndexReplace> & rNumRule) const; const ::com::sun::star::uno::Reference < ::com::sun::star::container::XIndexReplace >& GetNumRules() const diff --git a/sw/source/uibase/config/StoredChapterNumbering.cxx b/sw/source/uibase/config/StoredChapterNumbering.cxx index ee83535..245e884 100644 --- a/sw/source/uibase/config/StoredChapterNumbering.cxx +++ b/sw/source/uibase/config/StoredChapterNumbering.cxx @@ -346,7 +346,7 @@ public: uno::Reference<container::XIndexReplace> const xRule( new sw::StoredChapterNumberingRules(m_rNumRules, iter - m_Contexts.begin())); - (*iter)->FillUnoNumRule(xRule, 0); + (*iter)->FillUnoNumRule(xRule); // TODO: xmloff's outline-style import seems to ignore this??? uno::Reference<container::XNamed> const xNamed(xRule, uno::UNO_QUERY); xNamed->setName((*iter)->GetDisplayName()); diff --git a/xmloff/source/draw/XMLShapePropertySetContext.cxx b/xmloff/source/draw/XMLShapePropertySetContext.cxx index e4599f3..f4f9880 100644 --- a/xmloff/source/draw/XMLShapePropertySetContext.cxx +++ b/xmloff/source/draw/XMLShapePropertySetContext.cxx @@ -55,7 +55,7 @@ void XMLShapePropertySetContext::EndElement() SvxXMLListStyleContext* pBulletStyle = static_cast<SvxXMLListStyleContext*>(&mxBulletStyle); xNumRule = SvxXMLListStyleContext::CreateNumRule( GetImport().GetModel() ); if( xNumRule.is() ) - pBulletStyle->FillUnoNumRule(xNumRule, NULL /* const SvI18NMap * ??? */ ); + pBulletStyle->FillUnoNumRule(xNumRule); } Any aAny; diff --git a/xmloff/source/draw/XMLShapeStyleContext.cxx b/xmloff/source/draw/XMLShapeStyleContext.cxx index f3d1d19..720ac4c 100644 --- a/xmloff/source/draw/XMLShapeStyleContext.cxx +++ b/xmloff/source/draw/XMLShapeStyleContext.cxx @@ -175,7 +175,7 @@ void XMLShapeStyleContext::FillPropertySet( const Reference< beans::XPropertySet if( pListStyle ) { uno::Reference< container::XIndexReplace > xNumRule( SvxXMLListStyleContext::CreateNumRule( GetImport().GetModel() ) ); - pListStyle->FillUnoNumRule(xNumRule, NULL /* const SvI18NMap * ??? */ ); + pListStyle->FillUnoNumRule(xNumRule); property->maValue <<= xNumRule; } else diff --git a/xmloff/source/style/xmlnumi.cxx b/xmloff/source/style/xmlnumi.cxx index 16a7c79..c88c909 100644 --- a/xmloff/source/style/xmlnumi.cxx +++ b/xmloff/source/style/xmlnumi.cxx @@ -44,7 +44,6 @@ #include <xmloff/XMLBase64ImportContext.hxx> #include <xmloff/xmltoken.hxx> -#include <xmloff/i18nmap.hxx> #include <xmloff/xmluconv.hxx> #include "fonthdl.hxx" #include <xmloff/XMLFontStylesContext.hxx> @@ -223,8 +222,7 @@ public: const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE; sal_Int32 GetLevel() const { return nLevel; } - Sequence<beans::PropertyValue> GetProperties( - const SvI18NMap *pI18NMap=0 ); + Sequence<beans::PropertyValue> GetProperties(); inline void SetPosAndSpaceMode( sal_Int16 eValue ) { @@ -402,8 +400,7 @@ SvXMLImportContext *SvxXMLListLevelStyleContext_Impl::CreateChildContext( return pContext; } -Sequence<beans::PropertyValue> SvxXMLListLevelStyleContext_Impl::GetProperties( - const SvI18NMap *pI18NMap ) +Sequence<beans::PropertyValue> SvxXMLListLevelStyleContext_Impl::GetProperties() { sal_Int16 eType = NumberingType::NUMBER_NONE; @@ -496,8 +493,6 @@ Sequence<beans::PropertyValue> SvxXMLListLevelStyleContext_Impl::GetProperties( OUString sDisplayTextStyleName = GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_TEXT, sTextStyleName ); OUString sStyleName = sDisplayTextStyleName; - if( !sStyleName.isEmpty() && pI18NMap ) - sStyleName = pI18NMap->Get( SFX_STYLE_FAMILY_CHAR, sStyleName ); pProps[nPos].Name = "CharStyleName"; pProps[nPos++].Value <<= sDisplayTextStyleName; @@ -1087,8 +1082,7 @@ SvXMLImportContext *SvxXMLListStyleContext::CreateChildContext( } void SvxXMLListStyleContext::FillUnoNumRule( - const Reference< container::XIndexReplace > & rNumRule, - const SvI18NMap *pI18NMap ) const + const Reference<container::XIndexReplace> & rNumRule) const { try { @@ -1104,7 +1098,7 @@ void SvxXMLListStyleContext::FillUnoNumRule( if( nLevel >= 0 && nLevel < l_nLevels ) { Sequence<beans::PropertyValue> aProps = - pLevelStyle->GetProperties( pI18NMap ); + pLevelStyle->GetProperties(); Any aAny; aAny <<= aProps; rNumRule->replaceByIndex( nLevel, aAny ); @@ -1142,7 +1136,7 @@ void SvxXMLListStyleContext::CreateAndInsertLate( bool bOverwrite ) // We don't set xNumberingRules here, to avoid using them // as numbering rules. if( rNumRule.is() ) - FillUnoNumRule( rNumRule, 0 ); + FillUnoNumRule(rNumRule); } } else @@ -1212,7 +1206,7 @@ void SvxXMLListStyleContext::CreateAndInsertLate( bool bOverwrite ) nLevels = xNumRules->getCount(); if( bOverwrite || bNew ) { - FillUnoNumRule( xNumRules, 0 ); + FillUnoNumRule(xNumRules); aAny <<= xNumRules; xPropSet->setPropertyValue( sNumberingRules, aAny ); } @@ -1241,7 +1235,7 @@ void SvxXMLListStyleContext::CreateAndInsertAuto() const GetImport().GetModel() ); ((SvxXMLListStyleContext *)this)->nLevels = xNumRules->getCount(); - FillUnoNumRule( xNumRules, 0 ); + FillUnoNumRule(xNumRules); } Reference < XIndexReplace > SvxXMLListStyleContext::CreateNumRule( commit 1535f39388223de53e4b923c6f7bb71ee32c1858 Author: Michael Stahl <mst...@redhat.com> Date: Fri Nov 7 19:11:11 2014 +0100 sw: store Outline Numbering as ODF fragment instead of SfxPoolItems This should be less fragile and re-uses some xmloff and unocore code. Storing from ~SwBaseNumRules() does not work because other gobals that the export code relies on are already dead at the time it is called from a terminate() listener, so store when the dialog updates a format. Change-Id: I4e148b82d0a338ec7ffa6429c6e162db79f8c44e diff --git a/include/xmloff/xmlnume.hxx b/include/xmloff/xmlnume.hxx index 8418ef2..761872c 100644 --- a/include/xmloff/xmlnume.hxx +++ b/include/xmloff/xmlnume.hxx @@ -37,7 +37,7 @@ class SvXMLExportItemMapper; class SvXMLExport; class XMLTextListAutoStylePool; -class SvxXMLNumRuleExport +class XMLOFF_DLLPUBLIC SvxXMLNumRuleExport { SvXMLExport& rExport; const OUString sNumberingRules; @@ -49,12 +49,7 @@ class SvxXMLNumRuleExport // to be suppressed on writing ODF 1.0 respectively ODF 1.1 bool mbExportPositionAndSpaceModeLabelAlignment; - void exportLevelStyles( - const ::com::sun::star::uno::Reference< - ::com::sun::star::container::XIndexReplace > & xNumRule, - bool bOutline=false ); - - void exportLevelStyle( + SAL_DLLPRIVATE void exportLevelStyle( sal_Int32 nLevel, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProps, @@ -64,11 +59,11 @@ protected: // This method may be overloaded to add attributes to the <list-style> // element. - virtual void AddListStyleAttributes(); + SAL_DLLPRIVATE virtual void AddListStyleAttributes(); - bool exportStyle( const ::com::sun::star::uno::Reference< + SAL_DLLPRIVATE bool exportStyle( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& rStyle ); - void exportOutline(); + SAL_DLLPRIVATE void exportOutline(); SvXMLExport& GetExport() { return rExport; } @@ -77,6 +72,12 @@ public: SvxXMLNumRuleExport( SvXMLExport& rExport ); virtual ~SvxXMLNumRuleExport(); + // should be private but sw::StoredChapterNumberingExport needs it + void exportLevelStyles( + const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XIndexReplace > & xNumRule, + bool bOutline=false ); + void exportStyles( bool bUsed, XMLTextListAutoStylePool *pPool, bool bExportChapterNumbering = true ); diff --git a/include/xmloff/xmlnumi.hxx b/include/xmloff/xmlnumi.hxx index 4e7bc15..413b9ff 100644 --- a/include/xmloff/xmlnumi.hxx +++ b/include/xmloff/xmlnumi.hxx @@ -30,7 +30,8 @@ class SvI18NMap; class SvxXMLListLevelStyleContext_Impl; typedef std::vector<SvxXMLListLevelStyleContext_Impl *> SvxXMLListStyle_Impl; -class SvxXMLListStyleContext : public SvXMLStyleContext +class XMLOFF_DLLPUBLIC SvxXMLListStyleContext + : public SvXMLStyleContext { const OUString sIsPhysical; const OUString sNumberingRules; @@ -47,7 +48,7 @@ class SvxXMLListStyleContext : public SvXMLStyleContext protected: - virtual void SetAttribute( sal_uInt16 nPrefixKey, + SAL_DLLPRIVATE virtual void SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName, const OUString& rValue ) SAL_OVERRIDE; diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk index 09d9b0c..d51615b 100644 --- a/sw/Library_sw.mk +++ b/sw/Library_sw.mk @@ -574,6 +574,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\ sw/source/uibase/cctrl/popbox \ sw/source/uibase/cctrl/swlbox \ sw/source/uibase/chrdlg/ccoll \ + sw/source/uibase/config/StoredChapterNumbering \ sw/source/uibase/config/barcfg \ sw/source/uibase/config/caption \ sw/source/uibase/config/cfgitems \ diff --git a/sw/source/uibase/config/StoredChapterNumbering.cxx b/sw/source/uibase/config/StoredChapterNumbering.cxx new file mode 100644 index 0000000..ee83535 --- /dev/null +++ b/sw/source/uibase/config/StoredChapterNumbering.cxx @@ -0,0 +1,496 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <uinums.hxx> + +#include <cppuhelper/implbase2.hxx> + +#include <com/sun/star/container/XIndexReplace.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <com/sun/star/util/MeasureUnit.hpp> +#include <com/sun/star/xml/sax/Parser.hpp> +#include <com/sun/star/xml/sax/Writer.hpp> + +#include <comphelper/processfactory.hxx> + +#include <unotools/streamwrap.hxx> + +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmlnume.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlnumi.hxx> + +#include <vcl/svapp.hxx> + +#include <unosett.hxx> + + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +namespace sw { + +class StoredChapterNumberingRules + : public ::cppu::WeakImplHelper2<container::XNamed,container::XIndexReplace> +{ +private: + // TODO in case this ever becomes accessible via api need a invalidate + SwBaseNumRules & m_rNumRules; + sal_uInt16 const m_nIndex; + + SwNumRulesWithName * GetOrCreateRules() + { + SwNumRulesWithName const* pRules(m_rNumRules.GetRules(m_nIndex)); + if (!pRules) + { + m_rNumRules.CreateEmptyNumRule(m_nIndex); + pRules = m_rNumRules.GetRules(m_nIndex); + assert(pRules); + } + return const_cast<SwNumRulesWithName*>(pRules); + } + +public: + StoredChapterNumberingRules( + SwBaseNumRules & rNumRules, sal_uInt16 const nIndex) + : m_rNumRules(rNumRules) + , m_nIndex(nIndex) + { + assert(m_nIndex < SwBaseNumRules::nMaxRules); + } + + // XNamed + virtual OUString SAL_CALL getName() + throw (uno::RuntimeException, std::exception) SAL_OVERRIDE + { + SolarMutexGuard g; + SwNumRulesWithName const* pRules(m_rNumRules.GetRules(m_nIndex)); + if (!pRules) + { + return OUString(); + } + return pRules->GetName(); + } + + virtual void SAL_CALL setName(OUString const& rName) + throw (uno::RuntimeException, std::exception) SAL_OVERRIDE + { + SolarMutexGuard g; + SwNumRulesWithName *const pRules(GetOrCreateRules()); + pRules->SetName(rName); + } + + // XElementAccess + virtual uno::Type SAL_CALL getElementType() + throw (uno::RuntimeException, std::exception) SAL_OVERRIDE + { + return ::cppu::UnoType<uno::Sequence<beans::PropertyValue>>::get(); + } + + virtual ::sal_Bool SAL_CALL hasElements() + throw (uno::RuntimeException, std::exception) SAL_OVERRIDE + { + return sal_True; + } + + // XIndexAccess + virtual sal_Int32 SAL_CALL getCount() + throw (uno::RuntimeException, std::exception) SAL_OVERRIDE + { + return MAXLEVEL; + } + + virtual uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) + throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, + uno::RuntimeException, std::exception) SAL_OVERRIDE + { + if (nIndex < 0 || MAXLEVEL <= nIndex) + throw lang::IndexOutOfBoundsException(); + + SolarMutexGuard g; + SwNumRulesWithName const* pRules(m_rNumRules.GetRules(m_nIndex)); + if (!pRules) + { + return uno::Any(); + } + SwNumFmt const* pNumFmt(0); + OUString const* pCharStyleName(0); + pRules->GetNumFmt(nIndex, pNumFmt, pCharStyleName); + if (!pNumFmt) + { // the dialog only fills in those levels that are non-default + return uno::Any(); // the export will ignore this level, yay + } + assert(pCharStyleName); + OUString dummy; // pass in empty HeadingStyleName - can't import anyway + uno::Sequence<beans::PropertyValue> const ret( + SwXNumberingRules::GetPropertiesForNumFmt( + *pNumFmt, *pCharStyleName, &dummy)); + return uno::makeAny(ret); + } + + // XIndexReplace + virtual void SAL_CALL replaceByIndex( + sal_Int32 nIndex, uno::Any const& rElement) + throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException, + std::exception) SAL_OVERRIDE + { + if (nIndex < 0 || MAXLEVEL <= nIndex) + throw lang::IndexOutOfBoundsException(); + uno::Sequence<beans::PropertyValue> props; + if (!(rElement >>= props)) + throw lang::IllegalArgumentException("invalid type", + static_cast< ::cppu::OWeakObject*>(this), 1); + + SolarMutexGuard g; + SwNumFmt numFmt; + OUString charStyleName; + SwXNumberingRules::SetPropertiesToNumFmt( + numFmt, + charStyleName, + 0, 0, 0, 0, 0, + props); + SwNumRulesWithName *const pRules(GetOrCreateRules()); + pRules->SetNumFmt(nIndex, numFmt, charStyleName); + } +}; + +class StoredChapterNumberingExport + : public SvXMLExport +{ +public: + StoredChapterNumberingExport( + uno::Reference<uno::XComponentContext> const& xContext, + OUString const& rFileName, + uno::Reference<xml::sax::XDocumentHandler> const& xHandler) + : SvXMLExport(xContext, "sw::StoredChapterNumberingExport", rFileName, + util::MeasureUnit::CM, xHandler) + { + _GetNamespaceMap().Add(GetXMLToken(XML_NP_OFFICE), + GetXMLToken(XML_N_OFFICE), XML_NAMESPACE_OFFICE); + _GetNamespaceMap().Add(GetXMLToken(XML_NP_TEXT), + GetXMLToken(XML_N_TEXT), XML_NAMESPACE_TEXT); + _GetNamespaceMap().Add(GetXMLToken(XML_NP_STYLE), + GetXMLToken(XML_N_STYLE), XML_NAMESPACE_STYLE); + _GetNamespaceMap().Add(GetXMLToken(XML_NP_FO), + GetXMLToken(XML_N_FO), XML_NAMESPACE_FO); + _GetNamespaceMap().Add(GetXMLToken(XML_NP_SVG), + GetXMLToken(XML_N_SVG), XML_NAMESPACE_SVG); + } + + virtual void _ExportAutoStyles() SAL_OVERRIDE {} + virtual void _ExportMasterStyles() SAL_OVERRIDE {} + virtual void _ExportContent() SAL_OVERRIDE {} + + void ExportRule(SvxXMLNumRuleExport & rExport, + uno::Reference<container::XIndexReplace> const& xRule) + { + uno::Reference<container::XNamed> const xNamed(xRule, uno::UNO_QUERY); + OUString const name(xNamed->getName()); + bool bEncoded(false); + AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, + EncodeStyleName(name, &bEncoded) ); + if (bEncoded) + { + AddAttribute(XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, name); + } + + SvXMLElementExport aElem( *this, XML_NAMESPACE_TEXT, + XML_OUTLINE_STYLE, true, true ); + rExport.exportLevelStyles(xRule, true); + } + + void ExportRules( + std::set<OUString> const& rCharStyles, + std::vector<uno::Reference<container::XIndexReplace>> const& rRules) + { + GetDocHandler()->startDocument(); + + AddAttribute(XML_NAMESPACE_NONE, + _GetNamespaceMap().GetAttrNameByKey(XML_NAMESPACE_OFFICE), + _GetNamespaceMap().GetNameByKey(XML_NAMESPACE_OFFICE)); + AddAttribute(XML_NAMESPACE_NONE, + _GetNamespaceMap().GetAttrNameByKey (XML_NAMESPACE_TEXT), + _GetNamespaceMap().GetNameByKey(XML_NAMESPACE_TEXT)); + AddAttribute(XML_NAMESPACE_NONE, + _GetNamespaceMap().GetAttrNameByKey(XML_NAMESPACE_STYLE), + _GetNamespaceMap().GetNameByKey(XML_NAMESPACE_STYLE)); + AddAttribute(XML_NAMESPACE_NONE, + _GetNamespaceMap().GetAttrNameByKey(XML_NAMESPACE_FO), + _GetNamespaceMap().GetNameByKey(XML_NAMESPACE_FO)); + AddAttribute(XML_NAMESPACE_NONE, + _GetNamespaceMap().GetAttrNameByKey(XML_NAMESPACE_SVG), + _GetNamespaceMap().GetNameByKey(XML_NAMESPACE_SVG)); + + { + // let's just have a office:styles as a dummy root + SvXMLElementExport styles(*this, + XML_NAMESPACE_OFFICE, XML_STYLES, true, true); + + // horrible hack for char styles to get display-name mapping + for (auto it = rCharStyles.begin(); it != rCharStyles.end(); ++it) + { + AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, XML_TEXT ); + bool bEncoded(false); + AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, + EncodeStyleName(*it, &bEncoded) ); + if (bEncoded) + { + AddAttribute(XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, *it); + } + + SvXMLElementExport style(*this, + XML_NAMESPACE_STYLE, XML_STYLE, true, true); + } + + SvxXMLNumRuleExport numRuleExport(*this); + + for (auto it = rRules.begin(); it != rRules.end(); ++it) + { + ExportRule(numRuleExport, *it); + } + } + + GetDocHandler()->endDocument(); + } +}; + +/** Dummy import context for style:style element that can just read the + attributes needed to map name to display-name. + Unfortunately the "real" context for this depends on some other things. + The mapping is necessary to import the text:style-name attribute + of the text:outline-level-style element. + */ +class StoredChapterNumberingDummyStyleContext + : public SvXMLImportContext +{ +public: + StoredChapterNumberingDummyStyleContext( + SvXMLImport & rImport, + sal_uInt16 const nPrefix, OUString const& rLocalName, + uno::Reference<xml::sax::XAttributeList> const& xAttrList) + : SvXMLImportContext(rImport, nPrefix, rLocalName) + { + OUString name; + OUString displayName; + sal_uInt16 nFamily(0); + for (sal_Int32 i = 0; i < xAttrList->getLength(); ++i) + { + OUString localName; + sal_uInt16 const prefix(rImport.GetNamespaceMap().GetKeyByAttrName( + xAttrList->getNameByIndex(i), &localName)); + OUString const& rValue = xAttrList->getValueByIndex(i); + + if (XML_NAMESPACE_STYLE == prefix) + { + if (IsXMLToken(localName, XML_FAMILY)) + { + if (IsXMLToken(rValue, XML_TEXT)) + { + nFamily = XML_STYLE_FAMILY_TEXT_TEXT; + } + } + else if (IsXMLToken(localName, XML_NAME)) + { + name = rValue; + } + else if (IsXMLToken(localName, XML_DISPLAY_NAME)) + { + displayName = rValue; + } + } + } + if (nFamily && !name.isEmpty() && !displayName.isEmpty()) + { + rImport.AddStyleDisplayName(nFamily, name, displayName); + } + } +}; + +class StoredChapterNumberingImport; + +class StoredChapterNumberingRootContext + : public SvXMLImportContext +{ +private: + SwBaseNumRules & m_rNumRules; + size_t m_nCounter; + ::std::vector<tools::SvRef<SvxXMLListStyleContext>> m_Contexts; + +public: + StoredChapterNumberingRootContext( + SwBaseNumRules & rNumRules, SvXMLImport & rImport, + sal_uInt16 const nPrefix, OUString const& rLocalName) + : SvXMLImportContext(rImport, nPrefix, rLocalName) + , m_rNumRules(rNumRules) + , m_nCounter(0) + { + } + + virtual void EndElement() SAL_OVERRIDE + { + assert(m_Contexts.size() < SwBaseNumRules::nMaxRules); + for (auto iter = m_Contexts.begin(); iter != m_Contexts.end(); ++iter) + { + uno::Reference<container::XIndexReplace> const xRule( + new sw::StoredChapterNumberingRules(m_rNumRules, + iter - m_Contexts.begin())); + (*iter)->FillUnoNumRule(xRule, 0); + // TODO: xmloff's outline-style import seems to ignore this??? + uno::Reference<container::XNamed> const xNamed(xRule, uno::UNO_QUERY); + xNamed->setName((*iter)->GetDisplayName()); + } + } + + virtual SvXMLImportContext * CreateChildContext( + sal_uInt16 const nPrefix, OUString const& rLocalName, + uno::Reference<xml::sax::XAttributeList> const& xAttrList) SAL_OVERRIDE + { + if (XML_NAMESPACE_TEXT == nPrefix && IsXMLToken(rLocalName, XML_OUTLINE_STYLE)) + { + ++m_nCounter; + if (m_nCounter <= SwBaseNumRules::nMaxRules) + { + SvxXMLListStyleContext *const pContext( + new SvxXMLListStyleContext(GetImport(), + nPrefix, rLocalName, xAttrList, true)); + m_Contexts.push_back(pContext); + return pContext; + } + } + else if (XML_NAMESPACE_STYLE == nPrefix && IsXMLToken(rLocalName, XML_STYLE)) + { + new StoredChapterNumberingDummyStyleContext( + GetImport(), nPrefix, rLocalName, xAttrList); + } + + return SvXMLImportContext::CreateChildContext( + nPrefix, rLocalName, xAttrList); + } +}; + +class StoredChapterNumberingImport + : public SvXMLImport +{ +private: + SwBaseNumRules & m_rNumRules; + +public: + StoredChapterNumberingImport( + uno::Reference<uno::XComponentContext> const& xContext, + SwBaseNumRules & rNumRules) + : SvXMLImport(xContext, "sw::StoredChapterNumberingImport", IMPORT_ALL) + , m_rNumRules(rNumRules) + { + } + + virtual SvXMLImportContext * CreateContext( + sal_uInt16 const nPrefix, OUString const& rLocalName, + uno::Reference<xml::sax::XAttributeList> const& xAttrList) SAL_OVERRIDE + { + if (XML_NAMESPACE_OFFICE == nPrefix && IsXMLToken(rLocalName, XML_STYLES)) + { + return new StoredChapterNumberingRootContext(m_rNumRules, + *this, nPrefix, rLocalName); + } + return SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList); + } +}; + +void ExportStoredChapterNumberingRules(SwBaseNumRules & rRules, + SvStream & rStream, OUString const& rFileName) +{ + uno::Reference<uno::XComponentContext> const xContext( + ::comphelper::getProcessComponentContext()); + + uno::Reference<io::XOutputStream> const xOutStream( + new ::utl::OOutputStreamWrapper(rStream)); + + uno::Reference<xml::sax::XWriter> const xWriter( + xml::sax::Writer::create(xContext)); + + uno::Reference<io::XActiveDataSource> const xADS(xWriter, uno::UNO_QUERY); + xADS->setOutputStream(xOutStream); + + uno::Reference<xml::sax::XDocumentHandler> const xHandler( + xWriter, uno::UNO_QUERY); + + StoredChapterNumberingExport exp(xContext, rFileName, xWriter); + + // if style name contains a space then name != display-name + // ... and the import needs to map from name to display-name then! + std::set<OUString> charStyles; + std::vector<uno::Reference<container::XIndexReplace>> numRules; + for (size_t i = 0; i < SwBaseNumRules::nMaxRules; ++i) + { + if (SwNumRulesWithName const* pRule = rRules.GetRules(i)) + { + for (size_t j = 0; j < MAXLEVEL; ++j) + { + SwNumFmt const* pDummy(0); + OUString const* pCharStyleName(0); + pRule->GetNumFmt(j, pDummy, pCharStyleName); + if (pCharStyleName && !pCharStyleName->isEmpty()) + { + charStyles.insert(*pCharStyleName); + } + } + numRules.push_back(new StoredChapterNumberingRules(rRules, i)); + } + } + + try + { + exp.ExportRules(charStyles, numRules); + } + catch (uno::Exception const& e) + { + SAL_WARN("sw.ui", + "ExportStoredChapterNumberingRules: exception: " << e.Message); + } +} + +void ImportStoredChapterNumberingRules(SwBaseNumRules & rRules, + SvStream & rStream, OUString const& rFileName) +{ + uno::Reference<uno::XComponentContext> const xContext( + ::comphelper::getProcessComponentContext()); + + uno::Reference<io::XInputStream> const xInStream( + new ::utl::OInputStreamWrapper(rStream)); + + uno::Reference<xml::sax::XParser> const xParser( + xml::sax::Parser::create(xContext)); + + uno::Reference<xml::sax::XDocumentHandler> const xHandler( + new StoredChapterNumberingImport(xContext, rRules)); + + xParser->setDocumentHandler(xHandler); + + xml::sax::InputSource const source(xInStream, "", "", rFileName); + + try + { + xParser->parseStream(source); + } + catch (uno::Exception const& e) + { + SAL_WARN("sw.ui", + "ImportStoredChapterNumberingRules: exception: " << e.Message); + } +} + +} // namespace sw + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/config/uinums.cxx b/sw/source/uibase/config/uinums.cxx index 0fe448d4..2d03704 100644 --- a/sw/source/uibase/config/uinums.cxx +++ b/sw/source/uibase/config/uinums.cxx @@ -63,7 +63,7 @@ SwBaseNumRules::SwBaseNumRules( const OUString& rFileName ) Init(); } -SwBaseNumRules::~SwBaseNumRules() +void SwBaseNumRules::Save() { if( bModified ) { @@ -78,14 +78,17 @@ SwBaseNumRules::~SwBaseNumRules() bool bRet = (pStream && pStream->GetError() == 0); if (bRet) { - Store( *pStream ); + sw::ExportStoredChapterNumberingRules(*this, *pStream, sFileName); pStream->Flush(); aMedium.Commit(); } } +} +SwBaseNumRules::~SwBaseNumRules() +{ for( sal_uInt16 i = 0; i < nMaxRules; ++i ) delete pNumRules[i]; } @@ -100,10 +103,17 @@ void SwBaseNumRules::Init() if( aOpt.SearchFile( sNm, SvtPathOptions::PATH_USERCONFIG )) { SfxMedium aStrm( sNm, STREAM_STD_READ ); - Load( *aStrm.GetInStream() ); + sw::ImportStoredChapterNumberingRules(*this, *aStrm.GetInStream(), sFileName); } } +void SwBaseNumRules::CreateEmptyNumRule(sal_uInt16 const nIndex) +{ + assert(nIndex < nMaxRules); + assert(!pNumRules[nIndex]); + pNumRules[nIndex] = new SwNumRulesWithName; +} + void SwBaseNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, sal_uInt16 nIdx) { OSL_ENSURE(nIdx < nMaxRules, "Array der NumRules ueberindiziert."); @@ -111,6 +121,7 @@ void SwBaseNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, sal_uInt16 n pNumRules[nIdx] = new SwNumRulesWithName( rCopy ); else *pNumRules[nIdx] = rCopy; + Save(); // store it immediately } bool SwBaseNumRules::Store(SvStream &rStream) @@ -191,6 +202,11 @@ SwNumRulesWithName::SwNumRulesWithName( const SwNumRule &rCopy, } } +SwNumRulesWithName::SwNumRulesWithName() +{ + memset(aFmts, 0, sizeof(aFmts)); +} + SwNumRulesWithName::SwNumRulesWithName( const SwNumRulesWithName& rCopy ) { memset( aFmts, 0, sizeof( aFmts )); @@ -279,6 +295,23 @@ void SwNumRulesWithName::Store( SvStream &rStream ) } } +void SwNumRulesWithName::GetNumFmt( + size_t const nIndex, SwNumFmt const*& rpNumFmt, OUString const*& rpName) const +{ + rpNumFmt = (aFmts[nIndex]) ? &aFmts[nIndex]->aFmt : 0; + rpName = (aFmts[nIndex]) ? &aFmts[nIndex]->sCharFmtName : 0; +} + +void SwNumRulesWithName::SetNumFmt( + size_t const nIndex, SwNumFmt const& rNumFmt, OUString const& rName) +{ + delete aFmts[nIndex]; + aFmts[nIndex] = new _SwNumFmtGlobal(rNumFmt); + aFmts[nIndex]->sCharFmtName = rName; + aFmts[nIndex]->nCharPoolId = USHRT_MAX; + aFmts[nIndex]->aItems.clear(); +} + SwNumRulesWithName::_SwNumFmtGlobal::_SwNumFmtGlobal( const SwNumFmt& rFmt ) : aFmt( rFmt ), nCharPoolId( USHRT_MAX ) { diff --git a/sw/source/uibase/inc/uinums.hxx b/sw/source/uibase/inc/uinums.hxx index b760957..bb1627e 100644 --- a/sw/source/uibase/inc/uinums.hxx +++ b/sw/source/uibase/inc/uinums.hxx @@ -27,6 +27,8 @@ class SfxPoolItem; class SwWrtShell; class SvStream; +namespace sw { class StoredChapterNumberingRules; } + #define MAX_NUM_RULES 9 typedef boost::ptr_vector<SfxPoolItem> _SwNumFmtsAttrs; @@ -38,6 +40,7 @@ class SW_DLLPUBLIC SwNumRulesWithName // (They should always be there!) class SAL_DLLPRIVATE _SwNumFmtGlobal { + friend class SwNumRulesWithName; SwNumFmt aFmt; OUString sCharFmtName; sal_uInt16 nCharPoolId; @@ -58,7 +61,11 @@ class SW_DLLPUBLIC SwNumRulesWithName _SwNumFmtGlobal* aFmts[ MAXLEVEL ]; protected: + friend class sw::StoredChapterNumberingRules; + friend class SwBaseNumRules; void SetName(const OUString& rSet) {maName = rSet;} + void SetNumFmt(size_t, SwNumFmt const&, OUString const&); + SwNumRulesWithName(); public: SwNumRulesWithName(const SwNumRule &, const OUString &); @@ -72,6 +79,8 @@ public: void MakeNumRule( SwWrtShell& rSh, SwNumRule& rChg ) const; void Store( SvStream& ); + + void GetNumFmt(size_t, SwNumFmt const*&, OUString const*&) const; }; class SwBaseNumRules @@ -88,12 +97,14 @@ protected: virtual bool Store(SvStream&); void Init(); + void Save(); public: SwBaseNumRules(const OUString& rFileName); virtual ~SwBaseNumRules(); inline const SwNumRulesWithName* GetRules(sal_uInt16 nIdx) const; + void CreateEmptyNumRule(sal_uInt16 nIdx); // for import virtual void ApplyNumRules( const SwNumRulesWithName &rCopy, sal_uInt16 nIdx); @@ -117,6 +128,17 @@ inline const SwNumRulesWithName *SwBaseNumRules::GetRules(sal_uInt16 nIdx) const return pNumRules[nIdx]; } + +namespace sw +{ + +void ExportStoredChapterNumberingRules( + SwBaseNumRules & rRules, SvStream & rStream, OUString const&); +void ImportStoredChapterNumberingRules( + SwBaseNumRules & rRules, SvStream & rStream, OUString const&); + +} // namespace sw + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 5c3cf76f79a7f0cb5fb09e627cf07195ad5a0ef5 Author: Michael Stahl <mst...@redhat.com> Date: Fri Nov 7 17:34:54 2014 +0100 sw: refactor SwXNumberingRules ... to get some static property getter setter functions. Change-Id: I3e69c0c01ee7ec2d17edbf06876c17cf4fce3833 diff --git a/sw/inc/unosett.hxx b/sw/inc/unosett.hxx index 93d0ca4..0e35bec 100644 --- a/sw/inc/unosett.hxx +++ b/sw/inc/unosett.hxx @@ -37,6 +37,7 @@ class SwDoc; class SwFmtCol; class SwDocShell; class SwNumRule; +class SwNumFmt; class SwXFootnoteProperties : public cppu::WeakAggImplHelper2 < @@ -204,6 +205,19 @@ public: static bool isInvalidStyle(const OUString &rName); void Invalidate() {pDocShell = 0;} OUString GetCreatedNumRuleName() const {return m_sCreatedNumRuleName;} + + static css::uno::Sequence<css::beans::PropertyValue> GetPropertiesForNumFmt( + const SwNumFmt& rFmt, OUString const& rCharFormatName, + OUString const* pHeadingStyleName); + static void SetPropertiesToNumFmt( + SwNumFmt & aFmt, + OUString & rCharStyleName, + OUString *const pBulletFontName, + OUString *const pHeadingStyleName, + OUString *const pParagraphStyleName, + SwDoc *const pDoc, SwDocShell *const pDocShell, + css::uno::Sequence<css::beans::PropertyValue> const& rProperties); + }; class SwXChapterNumbering : public SwXNumberingRules diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx index 9e411bb..687f027 100644 --- a/sw/source/core/unocore/unosett.cxx +++ b/sw/source/core/unocore/unosett.cxx @@ -1331,7 +1331,58 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetNumberingRuleByIndex( const SwNumFmt& rFmt = rNumRule.Get( (sal_uInt16)nIndex ); - bool bChapterNum = pDocShell != 0; + SwCharFmt* pCharFmt = rFmt.GetCharFmt(); + OUString CharStyleName; + if (pCharFmt) + CharStyleName = pCharFmt->GetName(); + + // Whether or not a style is present: the array entry overwrites this string + if (!m_sNewCharStyleNames[nIndex].isEmpty() && + !SwXNumberingRules::isInvalidStyle(m_sNewCharStyleNames[nIndex])) + { ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits