2010-10-14 08:30:41 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2011-03-31 10:05:04 +02:00
/*
* 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/.
*
* This file incorporates work covered by the following license notice :
*
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2006-09-16 19:55:52 +00:00
2017-04-14 08:42:15 +10:00
# include <memory>
2015-02-13 09:09:40 +01:00
# include <libxml/xmlwriter.h>
2010-10-09 21:10:37 -05:00
# include <sal/macros.h>
2000-09-18 23:08:29 +00:00
# include <hintids.hxx>
2010-01-08 18:32:51 +01:00
# include <editeng/ulspitem.hxx>
# include <editeng/lrspitem.hxx>
# include <editeng/fhgtitem.hxx>
2013-10-22 15:58:57 +03:00
# include <doc.hxx>
2000-09-18 23:08:29 +00:00
# include <fmtcol.hxx>
2007-01-23 07:30:31 +00:00
# include <fmtcolfunc.hxx>
2000-09-18 23:08:29 +00:00
# include <hints.hxx>
# include <calc.hxx>
# include <node.hxx>
2004-11-26 12:24:32 +00:00
# include <numrule.hxx>
# include <paratr.hxx>
2015-03-18 13:58:25 +01:00
# include <calbck.hxx>
2009-10-16 00:05:16 +02:00
# include <svl/intitem.hxx>
2009-01-07 11:57:24 +00:00
2015-12-28 13:56:23 +04:00
# include <o3tl/make_unique.hxx>
2015-05-20 13:05:49 +02:00
namespace TextFormatCollFunc
2007-01-23 07:30:31 +00:00
{
2011-02-02 20:41:40 +09:00
// #i71574#
2015-05-20 13:05:49 +02:00
void CheckTextFormatCollForDeletionOfAssignmentToOutlineStyle (
SwFormat * pFormat ,
2008-06-13 08:36:21 +00:00
const SwNumRuleItem * pNewNumRuleItem )
2007-01-23 07:30:31 +00:00
{
2015-05-20 13:05:49 +02:00
SwTextFormatColl * pTextFormatColl = dynamic_cast < SwTextFormatColl * > ( pFormat ) ;
if ( ! pTextFormatColl )
2007-01-23 07:30:31 +00:00
{
2015-05-20 13:05:49 +02:00
OSL_FAIL ( " <TextFormatCollFunc::CheckTextFormatCollFuncForDeletionOfAssignmentToOutlineStyle> - misuse of method - it's only for instances of <SwTextFormatColl> " ) ;
2008-06-13 08:36:21 +00:00
return ;
2007-01-23 07:30:31 +00:00
}
2008-06-13 08:36:21 +00:00
2011-02-02 20:41:40 +09:00
// #i73790#
2015-05-20 13:05:49 +02:00
if ( ! pTextFormatColl - > StayAssignedToListLevelOfOutlineStyle ( ) & &
pTextFormatColl - > IsAssignedToListLevelOfOutlineStyle ( ) )
2007-01-23 07:30:31 +00:00
{
2017-01-21 14:59:15 +00:00
if ( ! pNewNumRuleItem )
2007-01-23 07:30:31 +00:00
{
2017-01-21 14:59:15 +00:00
( void ) pTextFormatColl - > GetItemState ( RES_PARATR_NUMRULE , false , reinterpret_cast < const SfxPoolItem * * > ( & pNewNumRuleItem ) ) ;
2008-06-13 08:36:21 +00:00
}
2017-01-21 14:59:15 +00:00
if ( pNewNumRuleItem )
2008-06-13 08:36:21 +00:00
{
2013-10-16 09:32:03 +02:00
OUString sNumRuleName = pNewNumRuleItem - > GetValue ( ) ;
if ( sNumRuleName . isEmpty ( ) | |
2015-05-20 13:05:49 +02:00
sNumRuleName ! = pTextFormatColl - > GetDoc ( ) - > GetOutlineNumRule ( ) - > GetName ( ) )
2008-06-13 08:36:21 +00:00
{
// delete assignment of paragraph style to list level of outline style.
2015-05-20 13:05:49 +02:00
pTextFormatColl - > DeleteAssignmentToListLevelOfOutlineStyle ( ) ;
2008-06-13 08:36:21 +00:00
}
2007-01-23 07:30:31 +00:00
}
}
}
2008-06-13 08:36:21 +00:00
2015-05-20 13:05:49 +02:00
SwNumRule * GetNumRule ( SwTextFormatColl & rTextFormatColl )
2008-06-13 08:36:21 +00:00
{
2015-11-10 10:25:48 +01:00
SwNumRule * pNumRule ( nullptr ) ;
2008-06-13 08:36:21 +00:00
2017-01-21 14:59:57 +00:00
const SwNumRuleItem * pNumRuleItem ( nullptr ) ;
( void ) rTextFormatColl . GetItemState ( RES_PARATR_NUMRULE , false , reinterpret_cast < const SfxPoolItem * * > ( & pNumRuleItem ) ) ;
if ( pNumRuleItem )
2008-06-13 08:36:21 +00:00
{
2013-10-16 09:32:03 +02:00
const OUString sNumRuleName = pNumRuleItem - > GetValue ( ) ;
if ( ! sNumRuleName . isEmpty ( ) )
2008-06-13 08:36:21 +00:00
{
2015-05-20 13:05:49 +02:00
pNumRule = rTextFormatColl . GetDoc ( ) - > FindNumRulePtr ( sNumRuleName ) ;
2008-06-13 08:36:21 +00:00
}
}
return pNumRule ;
}
2015-05-20 13:05:49 +02:00
void AddToNumRule ( SwTextFormatColl & rTextFormatColl )
2008-06-13 08:36:21 +00:00
{
2015-05-20 13:05:49 +02:00
SwNumRule * pNumRule = GetNumRule ( rTextFormatColl ) ;
2008-06-13 08:36:21 +00:00
if ( pNumRule )
{
2015-05-20 13:05:49 +02:00
pNumRule - > AddParagraphStyle ( rTextFormatColl ) ;
2008-06-13 08:36:21 +00:00
}
}
2015-05-20 13:05:49 +02:00
void RemoveFromNumRule ( SwTextFormatColl & rTextFormatColl )
2008-06-13 08:36:21 +00:00
{
2015-05-20 13:05:49 +02:00
SwNumRule * pNumRule = GetNumRule ( rTextFormatColl ) ;
2008-06-13 08:36:21 +00:00
if ( pNumRule )
{
2015-05-20 13:05:49 +02:00
pNumRule - > RemoveParagraphStyle ( rTextFormatColl ) ;
2008-06-13 08:36:21 +00:00
}
}
2015-05-20 13:05:49 +02:00
} // end of namespace TextFormatCollFunc
2007-01-23 07:30:31 +00:00
2015-05-20 13:05:49 +02:00
void SwTextFormatColl : : Modify ( const SfxPoolItem * pOld , const SfxPoolItem * pNew )
2000-09-18 23:08:29 +00:00
{
if ( GetDoc ( ) - > IsInDtor ( ) )
{
2015-05-20 13:05:49 +02:00
SwFormatColl : : Modify ( pOld , pNew ) ;
2000-09-18 23:08:29 +00:00
return ;
}
2011-02-02 20:41:40 +09:00
bool bNewParent ( false ) ; // #i66431# - adjust type of <bNewParent>
2015-11-10 10:25:48 +01:00
const SvxULSpaceItem * pNewULSpace = nullptr , * pOldULSpace = nullptr ;
const SvxLRSpaceItem * pNewLRSpace = nullptr , * pOldLRSpace = nullptr ;
const SvxFontHeightItem * aFontSizeArr [ 3 ] = { nullptr , nullptr , nullptr } ;
2011-02-02 20:41:40 +09:00
// #i70223#
2013-04-07 21:29:02 +02:00
const bool bAssignedToListLevelOfOutlineStyle ( IsAssignedToListLevelOfOutlineStyle ( ) ) ;
2015-11-10 10:25:48 +01:00
const SwNumRuleItem * pNewNumRuleItem ( nullptr ) ;
2000-11-09 18:06:22 +00:00
2015-11-10 10:25:48 +01:00
const SwAttrSetChg * pNewChgSet = nullptr , * pOldChgSet = nullptr ;
2000-09-18 23:08:29 +00:00
switch ( pOld ? pOld - > Which ( ) : pNew ? pNew - > Which ( ) : 0 )
{
case RES_ATTRSET_CHG :
2012-01-12 16:38:32 +01:00
// Only recalculate if we're not the sender!
2014-11-14 16:10:52 +02:00
pNewChgSet = static_cast < const SwAttrSetChg * > ( pNew ) ;
pOldChgSet = static_cast < const SwAttrSetChg * > ( pOld ) ;
2000-09-18 23:08:29 +00:00
pNewChgSet - > GetChgSet ( ) - > GetItemState (
2015-01-22 08:11:58 +01:00
RES_LR_SPACE , false , reinterpret_cast < const SfxPoolItem * * > ( & pNewLRSpace ) ) ;
2000-09-18 23:08:29 +00:00
pNewChgSet - > GetChgSet ( ) - > GetItemState (
2015-01-22 08:11:58 +01:00
RES_UL_SPACE , false , reinterpret_cast < const SfxPoolItem * * > ( & pNewULSpace ) ) ;
2000-11-09 18:06:22 +00:00
pNewChgSet - > GetChgSet ( ) - > GetItemState ( RES_CHRATR_FONTSIZE ,
2015-01-22 08:11:58 +01:00
false , reinterpret_cast < const SfxPoolItem * * > ( & ( aFontSizeArr [ 0 ] ) ) ) ;
2000-11-09 18:06:22 +00:00
pNewChgSet - > GetChgSet ( ) - > GetItemState ( RES_CHRATR_CJK_FONTSIZE ,
2015-01-22 08:11:58 +01:00
false , reinterpret_cast < const SfxPoolItem * * > ( & ( aFontSizeArr [ 1 ] ) ) ) ;
2000-11-09 18:06:22 +00:00
pNewChgSet - > GetChgSet ( ) - > GetItemState ( RES_CHRATR_CTL_FONTSIZE ,
2015-01-22 08:11:58 +01:00
false , reinterpret_cast < const SfxPoolItem * * > ( & ( aFontSizeArr [ 2 ] ) ) ) ;
2011-02-02 20:41:40 +09:00
// #i70223#, #i84745#
2008-01-29 07:37:51 +00:00
// check, if attribute set is applied to this paragraph style
if ( bAssignedToListLevelOfOutlineStyle & &
pNewChgSet - > GetTheChgdSet ( ) = = & GetAttrSet ( ) )
2006-11-01 14:10:48 +00:00
{
2014-02-19 21:49:02 +01:00
pNewChgSet - > GetChgSet ( ) - > GetItemState ( RES_PARATR_NUMRULE , false ,
2015-01-22 08:11:58 +01:00
reinterpret_cast < const SfxPoolItem * * > ( & pNewNumRuleItem ) ) ;
2006-11-01 14:10:48 +00:00
}
2005-11-08 16:17:21 +00:00
2000-09-18 23:08:29 +00:00
break ;
case RES_FMT_CHG :
if ( GetAttrSet ( ) . GetParent ( ) )
{
const SfxItemSet * pParent = GetAttrSet ( ) . GetParent ( ) ;
2014-11-14 16:10:52 +02:00
pNewLRSpace = static_cast < const SvxLRSpaceItem * > ( & pParent - > Get ( RES_LR_SPACE ) ) ;
pNewULSpace = static_cast < const SvxULSpaceItem * > ( & pParent - > Get ( RES_UL_SPACE ) ) ;
aFontSizeArr [ 0 ] = static_cast < const SvxFontHeightItem * > ( & pParent - > Get ( RES_CHRATR_FONTSIZE ) ) ;
aFontSizeArr [ 1 ] = static_cast < const SvxFontHeightItem * > ( & pParent - > Get ( RES_CHRATR_CJK_FONTSIZE ) ) ;
aFontSizeArr [ 2 ] = static_cast < const SvxFontHeightItem * > ( & pParent - > Get ( RES_CHRATR_CTL_FONTSIZE ) ) ;
2011-02-02 20:41:40 +09:00
// #i66431# - modify has to be propagated, because of new parent format.
2006-07-13 10:30:42 +00:00
bNewParent = true ;
2000-09-18 23:08:29 +00:00
}
break ;
case RES_LR_SPACE :
2014-11-14 16:10:52 +02:00
pNewLRSpace = static_cast < const SvxLRSpaceItem * > ( pNew ) ;
2000-09-18 23:08:29 +00:00
break ;
case RES_UL_SPACE :
2014-11-14 16:10:52 +02:00
pNewULSpace = static_cast < const SvxULSpaceItem * > ( pNew ) ;
2000-09-18 23:08:29 +00:00
break ;
case RES_CHRATR_FONTSIZE :
2014-11-14 16:10:52 +02:00
aFontSizeArr [ 0 ] = static_cast < const SvxFontHeightItem * > ( pNew ) ;
2000-09-18 23:08:29 +00:00
break ;
2000-11-09 13:57:30 +00:00
case RES_CHRATR_CJK_FONTSIZE :
2014-11-14 16:10:52 +02:00
aFontSizeArr [ 1 ] = static_cast < const SvxFontHeightItem * > ( pNew ) ;
2000-11-09 13:57:30 +00:00
break ;
case RES_CHRATR_CTL_FONTSIZE :
2014-11-14 16:10:52 +02:00
aFontSizeArr [ 2 ] = static_cast < const SvxFontHeightItem * > ( pNew ) ;
2000-11-09 13:57:30 +00:00
break ;
2011-02-02 20:41:40 +09:00
// #i70223#
2006-11-01 14:10:48 +00:00
case RES_PARATR_NUMRULE :
2014-06-27 12:27:55 +00:00
if ( bAssignedToListLevelOfOutlineStyle )
2006-11-01 14:10:48 +00:00
{
2014-11-14 16:10:52 +02:00
pNewNumRuleItem = static_cast < const SwNumRuleItem * > ( pNew ) ;
2006-11-01 14:10:48 +00:00
}
2014-06-27 12:27:55 +00:00
break ;
2004-11-27 10:41:20 +00:00
default :
break ;
2000-09-18 23:08:29 +00:00
}
2011-02-02 20:41:40 +09:00
// #i70223#
2006-11-01 14:10:48 +00:00
if ( bAssignedToListLevelOfOutlineStyle & & pNewNumRuleItem )
{
2015-05-20 13:05:49 +02:00
TextFormatCollFunc : : CheckTextFormatCollForDeletionOfAssignmentToOutlineStyle (
2007-01-23 07:30:31 +00:00
this , pNewNumRuleItem ) ;
2006-11-01 14:10:48 +00:00
}
2014-01-17 17:11:45 +01:00
bool bContinue = true ;
2000-09-18 23:08:29 +00:00
2012-01-12 16:38:32 +01:00
// Check against the own attributes
2014-09-10 17:53:41 +02:00
if ( pNewLRSpace & & SfxItemState : : SET = = GetItemState ( RES_LR_SPACE , false ,
2015-01-22 08:11:58 +01:00
reinterpret_cast < const SfxPoolItem * * > ( & pOldLRSpace ) ) )
2000-09-18 23:08:29 +00:00
{
2012-01-12 16:38:32 +01:00
if ( pOldLRSpace ! = pNewLRSpace ) // Avoid recursion (SetAttr!)
2000-09-18 23:08:29 +00:00
{
2015-01-15 17:16:31 +00:00
bool bChg = false ;
2000-09-18 23:08:29 +00:00
SvxLRSpaceItem aNew ( * pOldLRSpace ) ;
2012-01-12 16:38:32 +01:00
// We had a relative value -> recalculate
2000-09-18 23:08:29 +00:00
if ( 100 ! = aNew . GetPropLeft ( ) )
{
2012-01-12 16:38:32 +01:00
long nTmp = aNew . GetLeft ( ) ; // keep so that we can compare
2000-09-18 23:08:29 +00:00
aNew . SetLeft ( pNewLRSpace - > GetLeft ( ) , aNew . GetPropLeft ( ) ) ;
bChg | = nTmp ! = aNew . GetLeft ( ) ;
}
2012-01-12 16:38:32 +01:00
// We had a relative value -> recalculate
2000-09-18 23:08:29 +00:00
if ( 100 ! = aNew . GetPropRight ( ) )
{
2012-01-12 16:38:32 +01:00
long nTmp = aNew . GetRight ( ) ; // keep so that we can compare
2000-09-18 23:08:29 +00:00
aNew . SetRight ( pNewLRSpace - > GetRight ( ) , aNew . GetPropRight ( ) ) ;
bChg | = nTmp ! = aNew . GetRight ( ) ;
}
2012-01-12 16:38:32 +01:00
// We had a relative value -> recalculate
2015-05-20 13:05:49 +02:00
if ( 100 ! = aNew . GetPropTextFirstLineOfst ( ) )
2000-09-18 23:08:29 +00:00
{
2015-05-20 13:05:49 +02:00
short nTmp = aNew . GetTextFirstLineOfst ( ) ; // keep so that we can compare
aNew . SetTextFirstLineOfst ( pNewLRSpace - > GetTextFirstLineOfst ( ) ,
aNew . GetPropTextFirstLineOfst ( ) ) ;
bChg | = nTmp ! = aNew . GetTextFirstLineOfst ( ) ;
2000-09-18 23:08:29 +00:00
}
if ( bChg )
{
2015-05-20 13:05:49 +02:00
SetFormatAttr ( aNew ) ;
2015-11-10 10:25:48 +01:00
bContinue = nullptr ! = pOldChgSet | | bNewParent ;
2000-09-18 23:08:29 +00:00
}
2012-01-12 16:38:32 +01:00
// We set it to absolute -> do not propagate it further, unless
// we set it!
2000-09-18 23:08:29 +00:00
else if ( pNewChgSet )
2013-09-26 19:22:14 +02:00
bContinue = pNewChgSet - > GetTheChgdSet ( ) = = & GetAttrSet ( ) ;
2000-09-18 23:08:29 +00:00
}
}
2014-09-10 17:53:41 +02:00
if ( pNewULSpace & & SfxItemState : : SET = = GetItemState (
2015-01-22 08:11:58 +01:00
RES_UL_SPACE , false , reinterpret_cast < const SfxPoolItem * * > ( & pOldULSpace ) ) & &
2012-01-12 16:38:32 +01:00
pOldULSpace ! = pNewULSpace ) // Avoid recursion (SetAttr!)
2000-09-18 23:08:29 +00:00
{
SvxULSpaceItem aNew ( * pOldULSpace ) ;
2014-01-17 17:11:45 +01:00
bool bChg = false ;
2012-01-12 16:38:32 +01:00
// We had a relative value -> recalculate
2000-09-18 23:08:29 +00:00
if ( 100 ! = aNew . GetPropUpper ( ) )
{
2012-01-12 16:38:32 +01:00
sal_uInt16 nTmp = aNew . GetUpper ( ) ; // keep so that we can compare
2000-09-18 23:08:29 +00:00
aNew . SetUpper ( pNewULSpace - > GetUpper ( ) , aNew . GetPropUpper ( ) ) ;
bChg | = nTmp ! = aNew . GetUpper ( ) ;
}
2012-01-12 16:38:32 +01:00
// We had a relative value -> recalculate
2000-09-18 23:08:29 +00:00
if ( 100 ! = aNew . GetPropLower ( ) )
{
2012-01-12 16:38:32 +01:00
sal_uInt16 nTmp = aNew . GetLower ( ) ; // keep so that we can compare
2000-09-18 23:08:29 +00:00
aNew . SetLower ( pNewULSpace - > GetLower ( ) , aNew . GetPropLower ( ) ) ;
bChg | = nTmp ! = aNew . GetLower ( ) ;
}
if ( bChg )
{
2015-05-20 13:05:49 +02:00
SetFormatAttr ( aNew ) ;
2015-11-10 10:25:48 +01:00
bContinue = nullptr ! = pOldChgSet | | bNewParent ;
2000-09-18 23:08:29 +00:00
}
2012-01-12 16:38:32 +01:00
// We set it to absolute -> do not propagate it further, unless
// we set it!
2000-09-18 23:08:29 +00:00
else if ( pNewChgSet )
2013-09-26 19:22:14 +02:00
bContinue = pNewChgSet - > GetTheChgdSet ( ) = = & GetAttrSet ( ) ;
2000-09-18 23:08:29 +00:00
}
2017-06-27 11:12:01 +02:00
for ( int nC = 0 ; nC < int ( SAL_N_ELEMENTS ( aFontSizeArr ) ) ; + + nC )
2000-09-18 23:08:29 +00:00
{
2014-11-14 16:10:52 +02:00
const SvxFontHeightItem * pFSize = aFontSizeArr [ nC ] , * pOldFSize ;
2014-09-10 17:53:41 +02:00
if ( pFSize & & SfxItemState : : SET = = GetItemState (
2015-01-22 08:11:58 +01:00
pFSize - > Which ( ) , false , reinterpret_cast < const SfxPoolItem * * > ( & pOldFSize ) ) & &
2012-01-12 16:38:32 +01:00
// Avoid recursion (SetAttr!)
2000-11-09 13:57:30 +00:00
pFSize ! = pOldFSize )
2000-09-18 23:08:29 +00:00
{
2005-02-04 10:15:05 +00:00
if ( 100 = = pOldFSize - > GetProp ( ) & &
2016-09-20 16:41:39 +02:00
MapUnit : : MapRelative = = pOldFSize - > GetPropUnit ( ) )
2000-09-18 23:08:29 +00:00
{
2012-01-12 16:38:32 +01:00
// We set it to absolute -> do not propagate it further, unless
// we set it!
2000-11-09 13:57:30 +00:00
if ( pNewChgSet )
2013-09-26 19:22:14 +02:00
bContinue = pNewChgSet - > GetTheChgdSet ( ) = = & GetAttrSet ( ) ;
2000-11-09 13:57:30 +00:00
}
else
{
2012-01-12 16:38:32 +01:00
// We had a relative value -> recalculate
sal_uInt32 nTmp = pOldFSize - > GetHeight ( ) ; // keep so that we can compare
2007-05-10 14:56:28 +00:00
SvxFontHeightItem aNew ( 240 , 100 , pFSize - > Which ( ) ) ;
2000-11-09 13:57:30 +00:00
aNew . SetHeight ( pFSize - > GetHeight ( ) , pOldFSize - > GetProp ( ) ,
pOldFSize - > GetPropUnit ( ) ) ;
if ( nTmp ! = aNew . GetHeight ( ) )
{
2015-05-20 13:05:49 +02:00
SetFormatAttr ( aNew ) ;
2015-11-10 10:25:48 +01:00
bContinue = nullptr ! = pOldChgSet | | bNewParent ;
2000-11-09 13:57:30 +00:00
}
2012-01-12 16:38:32 +01:00
// We set it to absolute -> do not propagate it further, unless
// we set it!
2000-11-09 13:57:30 +00:00
else if ( pNewChgSet )
2013-09-26 19:22:14 +02:00
bContinue = pNewChgSet - > GetTheChgdSet ( ) = = & GetAttrSet ( ) ;
2000-09-18 23:08:29 +00:00
}
}
}
2013-09-26 19:22:14 +02:00
if ( bContinue )
2015-05-20 13:05:49 +02:00
SwFormatColl : : Modify ( pOld , pNew ) ;
2000-09-18 23:08:29 +00:00
}
2015-05-20 13:05:49 +02:00
bool SwTextFormatColl : : IsAtDocNodeSet ( ) const
2000-09-18 23:08:29 +00:00
{
2015-05-20 13:05:49 +02:00
SwIterator < SwContentNode , SwFormatColl > aIter ( * this ) ;
2000-09-18 23:08:29 +00:00
const SwNodes & rNds = GetDoc ( ) - > GetNodes ( ) ;
2015-05-20 13:05:49 +02:00
for ( SwContentNode * pNode = aIter . First ( ) ; pNode ; pNode = aIter . Next ( ) )
2010-12-17 09:02:23 +01:00
if ( & ( pNode - > GetNodes ( ) ) = = & rNds )
2012-11-08 12:16:44 +09:00
return true ;
2000-09-18 23:08:29 +00:00
2012-11-08 12:16:44 +09:00
return false ;
2000-09-18 23:08:29 +00:00
}
2015-05-20 13:05:49 +02:00
bool SwTextFormatColl : : SetFormatAttr ( const SfxPoolItem & rAttr )
2008-06-13 08:36:21 +00:00
{
const bool bIsNumRuleItem = rAttr . Which ( ) = = RES_PARATR_NUMRULE ;
if ( bIsNumRuleItem )
{
2015-05-20 13:05:49 +02:00
TextFormatCollFunc : : RemoveFromNumRule ( * this ) ;
2008-06-13 08:36:21 +00:00
}
2015-05-20 13:05:49 +02:00
const bool bRet = SwFormatColl : : SetFormatAttr ( rAttr ) ;
2008-06-13 08:36:21 +00:00
if ( bIsNumRuleItem )
{
2015-05-20 13:05:49 +02:00
TextFormatCollFunc : : AddToNumRule ( * this ) ;
2008-06-13 08:36:21 +00:00
}
return bRet ;
}
2015-05-20 13:05:49 +02:00
bool SwTextFormatColl : : SetFormatAttr ( const SfxItemSet & rSet )
2008-06-13 08:36:21 +00:00
{
const bool bIsNumRuleItemAffected =
2014-09-10 17:53:41 +02:00
rSet . GetItemState ( RES_PARATR_NUMRULE , false ) = = SfxItemState : : SET ;
2008-06-13 08:36:21 +00:00
if ( bIsNumRuleItemAffected )
{
2015-05-20 13:05:49 +02:00
TextFormatCollFunc : : RemoveFromNumRule ( * this ) ;
2008-06-13 08:36:21 +00:00
}
2015-05-20 13:05:49 +02:00
const bool bRet = SwFormatColl : : SetFormatAttr ( rSet ) ;
2008-06-13 08:36:21 +00:00
if ( bIsNumRuleItemAffected )
{
2015-05-20 13:05:49 +02:00
TextFormatCollFunc : : AddToNumRule ( * this ) ;
2008-06-13 08:36:21 +00:00
}
return bRet ;
}
2015-05-20 13:05:49 +02:00
bool SwTextFormatColl : : ResetFormatAttr ( sal_uInt16 nWhich1 , sal_uInt16 nWhich2 )
2008-06-13 08:36:21 +00:00
{
const bool bIsNumRuleItemAffected =
( nWhich2 ! = 0 & & nWhich2 > nWhich1 )
? ( nWhich1 < = RES_PARATR_NUMRULE & &
RES_PARATR_NUMRULE < = nWhich2 )
: nWhich1 = = RES_PARATR_NUMRULE ;
if ( bIsNumRuleItemAffected )
{
2015-05-20 13:05:49 +02:00
TextFormatCollFunc : : RemoveFromNumRule ( * this ) ;
2008-06-13 08:36:21 +00:00
}
2015-05-20 13:05:49 +02:00
const bool bRet = SwFormatColl : : ResetFormatAttr ( nWhich1 , nWhich2 ) ;
2008-06-13 08:36:21 +00:00
return bRet ;
}
2011-02-02 20:41:40 +09:00
// #i73790#
2015-05-20 13:05:49 +02:00
sal_uInt16 SwTextFormatColl : : ResetAllFormatAttr ( )
2007-02-05 09:52:23 +00:00
{
const bool bOldState ( mbStayAssignedToListLevelOfOutlineStyle ) ;
mbStayAssignedToListLevelOfOutlineStyle = true ;
2011-02-02 20:41:40 +09:00
// #i70748#
2009-01-07 11:57:24 +00:00
// Outline level is no longer a member, it is a attribute now.
// Thus, it needs to be restored, if the paragraph style is assigned
// to the outline style
const int nAssignedOutlineStyleLevel = IsAssignedToListLevelOfOutlineStyle ( )
? GetAssignedOutlineStyleLevel ( )
: - 1 ;
2007-02-05 09:52:23 +00:00
2015-05-20 13:05:49 +02:00
sal_uInt16 nRet = SwFormatColl : : ResetAllFormatAttr ( ) ;
2007-02-05 09:52:23 +00:00
2011-02-02 20:41:40 +09:00
// #i70748#
2009-01-07 11:57:24 +00:00
if ( nAssignedOutlineStyleLevel ! = - 1 )
{
AssignToListLevelOfOutlineStyle ( nAssignedOutlineStyleLevel ) ;
}
2007-02-05 09:52:23 +00:00
mbStayAssignedToListLevelOfOutlineStyle = bOldState ;
return nRet ;
}
2015-05-20 13:05:49 +02:00
bool SwTextFormatColl : : AreListLevelIndentsApplicable ( ) const
2008-03-05 15:54:41 +00:00
{
bool bAreListLevelIndentsApplicable ( true ) ;
2014-09-10 17:53:41 +02:00
if ( GetItemState ( RES_PARATR_NUMRULE ) ! = SfxItemState : : SET )
2008-03-05 15:54:41 +00:00
{
// no list style applied to paragraph style
bAreListLevelIndentsApplicable = false ;
}
2014-09-10 17:53:41 +02:00
else if ( GetItemState ( RES_LR_SPACE , false ) = = SfxItemState : : SET )
2008-03-05 15:54:41 +00:00
{
// paragraph style has hard-set indent attributes
bAreListLevelIndentsApplicable = false ;
}
2014-09-10 17:53:41 +02:00
else if ( GetItemState ( RES_PARATR_NUMRULE , false ) = = SfxItemState : : SET )
2008-03-05 15:54:41 +00:00
{
// list style is directly applied to paragraph style and paragraph
// style has no hard-set indent attributes
bAreListLevelIndentsApplicable = true ;
}
else
{
// list style is applied through one of the parent paragraph styles and
// paragraph style has no hard-set indent attributes
// check parent paragraph styles
2015-05-20 13:05:49 +02:00
const SwTextFormatColl * pColl = dynamic_cast < const SwTextFormatColl * > ( DerivedFrom ( ) ) ;
2008-03-05 15:54:41 +00:00
while ( pColl )
{
2014-09-10 17:53:41 +02:00
if ( pColl - > GetAttrSet ( ) . GetItemState ( RES_LR_SPACE , false ) = = SfxItemState : : SET )
2008-03-05 15:54:41 +00:00
{
// indent attributes found in the paragraph style hierarchy.
bAreListLevelIndentsApplicable = false ;
break ;
}
2014-09-10 17:53:41 +02:00
if ( pColl - > GetAttrSet ( ) . GetItemState ( RES_PARATR_NUMRULE , false ) = = SfxItemState : : SET )
2008-03-05 15:54:41 +00:00
{
// paragraph style with the list style found and until now no
// indent attributes are found in the paragraph style hierarchy.
bAreListLevelIndentsApplicable = true ;
break ;
}
2015-05-20 13:05:49 +02:00
pColl = dynamic_cast < const SwTextFormatColl * > ( pColl - > DerivedFrom ( ) ) ;
2010-11-25 17:08:45 +01:00
OSL_ENSURE ( pColl ,
2015-05-20 13:05:49 +02:00
" <SwTextFormatColl::AreListLevelIndentsApplicable()> - something wrong in paragraph style hierarchy. The applied list style is not found. " ) ;
2008-03-05 15:54:41 +00:00
}
}
return bAreListLevelIndentsApplicable ;
}
2015-05-20 13:05:49 +02:00
void SwTextFormatColl : : dumpAsXml ( xmlTextWriterPtr pWriter ) const
2015-02-13 09:09:40 +01:00
{
2016-11-16 08:59:00 +02:00
xmlTextWriterStartElement ( pWriter , BAD_CAST ( " SwTextFormatColl " ) ) ;
2015-02-13 09:09:40 +01:00
xmlTextWriterWriteAttribute ( pWriter , BAD_CAST ( " name " ) , BAD_CAST ( GetName ( ) . toUtf8 ( ) . getStr ( ) ) ) ;
GetAttrSet ( ) . dumpAsXml ( pWriter ) ;
xmlTextWriterEndElement ( pWriter ) ;
}
2015-05-20 13:05:49 +02:00
void SwTextFormatColls : : dumpAsXml ( xmlTextWriterPtr pWriter ) const
2015-02-15 13:34:11 +01:00
{
2016-11-16 08:59:00 +02:00
xmlTextWriterStartElement ( pWriter , BAD_CAST ( " SwTextFormatColls " ) ) ;
2015-02-15 13:34:11 +01:00
for ( size_t i = 0 ; i < size ( ) ; + + i )
2015-05-20 13:05:49 +02:00
GetFormat ( i ) - > dumpAsXml ( pWriter ) ;
2015-02-15 13:34:11 +01:00
xmlTextWriterEndElement ( pWriter ) ;
}
2000-09-18 23:08:29 +00:00
//FEATURE::CONDCOLL
2017-02-10 13:48:36 +02:00
SwCollCondition : : SwCollCondition ( SwTextFormatColl * pColl , Master_CollCondition nMasterCond ,
2011-01-17 15:06:54 +01:00
sal_uLong nSubCond )
2017-02-10 13:48:36 +02:00
: SwClient ( pColl ) , m_nCondition ( nMasterCond ) ,
m_nSubCondition ( nSubCond )
2000-09-18 23:08:29 +00:00
{
}
SwCollCondition : : SwCollCondition ( const SwCollCondition & rCopy )
2017-02-10 13:48:36 +02:00
: SwClient ( const_cast < SwModify * > ( rCopy . GetRegisteredIn ( ) ) ) ,
m_nCondition ( rCopy . m_nCondition ) ,
m_nSubCondition ( rCopy . m_nSubCondition )
2000-09-18 23:08:29 +00:00
{
}
SwCollCondition : : ~ SwCollCondition ( )
{
}
2015-05-20 13:05:49 +02:00
void SwCollCondition : : RegisterToFormat ( SwFormat & rFormat )
2010-12-17 09:02:23 +01:00
{
2015-05-20 13:05:49 +02:00
rFormat . Add ( this ) ;
2010-12-17 09:02:23 +01:00
}
2014-01-17 17:11:45 +01:00
bool SwCollCondition : : operator = = ( const SwCollCondition & rCmp ) const
2000-09-18 23:08:29 +00:00
{
2017-02-10 13:48:36 +02:00
return ( m_nCondition = = rCmp . m_nCondition )
& & ( m_nSubCondition = = rCmp . m_nSubCondition ) ;
2000-09-18 23:08:29 +00:00
}
2017-02-10 13:48:36 +02:00
void SwCollCondition : : SetCondition ( Master_CollCondition nCond , sal_uLong nSubCond )
2000-09-18 23:08:29 +00:00
{
2015-11-02 09:07:56 +01:00
m_nCondition = nCond ;
2017-02-10 13:48:36 +02:00
m_nSubCondition = nSubCond ;
2000-09-18 23:08:29 +00:00
}
2015-05-20 13:05:49 +02:00
SwConditionTextFormatColl : : ~ SwConditionTextFormatColl ( )
2000-09-18 23:08:29 +00:00
{
}
2015-05-20 13:05:49 +02:00
const SwCollCondition * SwConditionTextFormatColl : : HasCondition (
2000-09-18 23:08:29 +00:00
const SwCollCondition & rCond ) const
{
2015-09-11 16:22:36 +02:00
for ( const auto & rpFnd : m_CondColls )
{
if ( * rpFnd = = rCond )
return rpFnd . get ( ) ;
}
2003-12-01 15:35:39 +00:00
2015-02-21 16:33:06 +01:00
return nullptr ;
2000-09-18 23:08:29 +00:00
}
2015-05-20 13:05:49 +02:00
void SwConditionTextFormatColl : : InsertCondition ( const SwCollCondition & rCond )
2000-09-18 23:08:29 +00:00
{
2015-09-11 16:22:36 +02:00
for ( SwFormatCollConditions : : size_type n = 0 ; n < m_CondColls . size ( ) ; + + n )
{
if ( * m_CondColls [ n ] = = rCond )
2000-09-18 23:08:29 +00:00
{
2015-09-11 16:22:36 +02:00
m_CondColls . erase ( m_CondColls . begin ( ) + n ) ;
2000-09-18 23:08:29 +00:00
break ;
}
2015-09-11 16:22:36 +02:00
}
2000-09-18 23:08:29 +00:00
2012-01-12 16:38:32 +01:00
// Not found -> so insert it
2015-12-28 13:56:23 +04:00
m_CondColls . push_back ( o3tl : : make_unique < SwCollCondition > ( rCond ) ) ;
2000-09-18 23:08:29 +00:00
}
2015-05-20 13:05:49 +02:00
bool SwConditionTextFormatColl : : RemoveCondition ( const SwCollCondition & rCond )
2000-09-18 23:08:29 +00:00
{
2012-11-08 12:16:44 +09:00
bool bRet = false ;
2015-09-11 16:22:36 +02:00
for ( SwFormatCollConditions : : size_type n = 0 ; n < m_CondColls . size ( ) ; + + n )
{
if ( * m_CondColls [ n ] = = rCond )
2000-09-18 23:08:29 +00:00
{
2015-09-11 16:22:36 +02:00
m_CondColls . erase ( m_CondColls . begin ( ) + n ) ;
2012-11-08 12:16:44 +09:00
bRet = true ;
2000-09-18 23:08:29 +00:00
}
2015-09-11 16:22:36 +02:00
}
2000-09-18 23:08:29 +00:00
return bRet ;
}
2015-05-20 13:05:49 +02:00
void SwConditionTextFormatColl : : SetConditions ( const SwFormatCollConditions & rCndClls )
2000-09-18 23:08:29 +00:00
{
2012-01-12 16:38:32 +01:00
// Copy the Conditions, but first delete the old ones
2015-09-11 16:22:36 +02:00
m_CondColls . clear ( ) ;
2000-09-18 23:08:29 +00:00
SwDoc & rDoc = * GetDoc ( ) ;
2015-09-11 16:22:36 +02:00
for ( const auto & rpFnd : rCndClls )
2000-09-18 23:08:29 +00:00
{
2015-09-11 16:22:36 +02:00
SwTextFormatColl * const pTmpColl = rpFnd - > GetTextFormatColl ( )
? rDoc . CopyTextColl ( * rpFnd - > GetTextFormatColl ( ) )
2015-11-10 10:25:48 +01:00
: nullptr ;
2015-09-11 16:22:36 +02:00
std : : unique_ptr < SwCollCondition > pNew ;
2017-02-10 13:48:36 +02:00
pNew . reset ( new SwCollCondition ( pTmpColl , rpFnd - > GetCondition ( ) ,
2015-09-11 16:22:36 +02:00
rpFnd - > GetSubCondition ( ) ) ) ;
m_CondColls . push_back ( std : : move ( pNew ) ) ;
2000-09-18 23:08:29 +00:00
}
}
2013-04-07 21:29:02 +02:00
2014-06-27 12:27:55 +00:00
// FEATURE::CONDCOLL
2015-05-20 13:05:49 +02:00
void SwTextFormatColl : : SetAttrOutlineLevel ( int nLevel )
2009-01-07 11:57:24 +00:00
{
2015-05-20 13:05:49 +02:00
OSL_ENSURE ( 0 < = nLevel & & nLevel < = MAXLEVEL , " SwTextFormatColl: Level Out Of Range " ) ;
SetFormatAttr ( SfxUInt16Item ( RES_PARATR_OUTLINELEVEL ,
2011-01-17 15:06:54 +01:00
static_cast < sal_uInt16 > ( nLevel ) ) ) ;
2009-01-07 11:57:24 +00:00
}
2000-09-18 23:08:29 +00:00
2015-05-20 13:05:49 +02:00
int SwTextFormatColl : : GetAttrOutlineLevel ( ) const
2004-11-26 12:24:32 +00:00
{
2015-05-20 13:05:49 +02:00
return static_cast < const SfxUInt16Item & > ( GetFormatAttr ( RES_PARATR_OUTLINELEVEL ) ) . GetValue ( ) ;
2004-11-26 12:24:32 +00:00
}
2015-05-20 13:05:49 +02:00
int SwTextFormatColl : : GetAssignedOutlineStyleLevel ( ) const
2009-01-07 11:57:24 +00:00
{
2010-11-25 17:08:45 +01:00
OSL_ENSURE ( IsAssignedToListLevelOfOutlineStyle ( ) ,
2015-05-20 13:05:49 +02:00
" <SwTextFormatColl::GetAssignedOutlineStyleLevel()> - misuse of method " ) ;
2009-01-07 11:57:24 +00:00
return GetAttrOutlineLevel ( ) - 1 ;
}
2015-05-20 13:05:49 +02:00
void SwTextFormatColl : : AssignToListLevelOfOutlineStyle ( const int nAssignedListLevel )
2009-01-07 11:57:24 +00:00
{
mbAssignedToOutlineStyle = true ;
SetAttrOutlineLevel ( nAssignedListLevel + 1 ) ;
2009-03-23 16:52:46 +00:00
2011-02-02 20:41:40 +09:00
// #i100277#
2015-05-20 13:05:49 +02:00
SwIterator < SwTextFormatColl , SwFormatColl > aIter ( * this ) ;
SwTextFormatColl * pDerivedTextFormatColl = aIter . First ( ) ;
2015-11-10 10:25:48 +01:00
while ( pDerivedTextFormatColl ! = nullptr )
2009-03-23 16:52:46 +00:00
{
2015-05-20 13:05:49 +02:00
if ( ! pDerivedTextFormatColl - > IsAssignedToListLevelOfOutlineStyle ( ) )
2009-03-23 16:52:46 +00:00
{
2015-05-20 13:05:49 +02:00
if ( pDerivedTextFormatColl - > GetItemState ( RES_PARATR_NUMRULE , false ) = = SfxItemState : : DEFAULT )
2009-03-23 16:52:46 +00:00
{
2013-10-16 11:18:56 +02:00
SwNumRuleItem aItem ( aEmptyOUStr ) ;
2015-05-20 13:05:49 +02:00
pDerivedTextFormatColl - > SetFormatAttr ( aItem ) ;
2009-03-23 16:52:46 +00:00
}
2015-05-20 13:05:49 +02:00
if ( pDerivedTextFormatColl - > GetItemState ( RES_PARATR_OUTLINELEVEL , false ) = = SfxItemState : : DEFAULT )
2009-03-23 16:52:46 +00:00
{
2015-05-20 13:05:49 +02:00
pDerivedTextFormatColl - > SetAttrOutlineLevel ( 0 ) ;
2009-03-23 16:52:46 +00:00
}
}
2015-05-20 13:05:49 +02:00
pDerivedTextFormatColl = aIter . Next ( ) ;
2009-03-23 16:52:46 +00:00
}
2009-01-07 11:57:24 +00:00
}
2016-03-22 10:58:54 +02:00
void SwTextFormatColl : : DeleteAssignmentToListLevelOfOutlineStyle ( )
2009-01-07 11:57:24 +00:00
{
mbAssignedToOutlineStyle = false ;
2016-03-22 10:58:54 +02:00
ResetFormatAttr ( RES_PARATR_OUTLINELEVEL ) ;
2009-01-07 11:57:24 +00:00
}
2010-10-14 08:30:41 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */