1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLTextNumRuleInfo.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include <tools/debug.hxx>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <com/sun/star/container/XIndexReplace.hpp>
38 #include <com/sun/star/style/NumberingType.hpp>
39 #include <com/sun/star/container/XNamed.hpp>
40 #include "XMLTextNumRuleInfo.hxx"
41 // --> OD 2008-04-25 #refactorlists#
42 #include "XMLTextListAutoStylePool.hxx"
45 using ::rtl::OUString
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::beans
;
49 using namespace ::com::sun::star::container
;
50 using namespace ::com::sun::star::style
;
52 // --> OD 2008-05-08 #refactorlists#
53 // Complete refactoring of the class and enhancement of the class for lists.
54 XMLTextNumRuleInfo::XMLTextNumRuleInfo()
55 : msNumberingRules(RTL_CONSTASCII_USTRINGPARAM("NumberingRules"))
56 , msNumberingLevel(RTL_CONSTASCII_USTRINGPARAM("NumberingLevel"))
57 , msNumberingStartValue(RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue"))
58 , msNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType"))
59 , msParaIsNumberingRestart(RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart"))
60 , msNumberingIsNumber(RTL_CONSTASCII_USTRINGPARAM("NumberingIsNumber"))
61 , msNumberingIsOutline(RTL_CONSTASCII_USTRINGPARAM("NumberingIsOutline"))
62 , msPropNameListId(RTL_CONSTASCII_USTRINGPARAM("ListId"))
63 , msPropNameStartWith(RTL_CONSTASCII_USTRINGPARAM("StartWith"))
64 // --> OD 2008-11-26 #158694#
65 , msContinueingPreviousSubTree(RTL_CONSTASCII_USTRINGPARAM("ContinueingPreviousSubTree"))
66 , msListLabelStringProp(RTL_CONSTASCII_USTRINGPARAM("ListLabelString"))
71 , mnListStartValue( -1 )
72 , mnNumberingType( NumberingType::CHAR_SPECIAL
)
74 , mbIsNumbered( sal_False
)
75 , mbIsRestart( sal_False
)
76 , mnListLevelStartValue( -1 )
77 , mbOutlineStyleAsNormalListStyle( sal_False
)
82 // --> OD 2006-09-27 #i69627#
83 void XMLTextNumRuleInfo::Set(
84 const ::com::sun::star::uno::Reference
<
85 ::com::sun::star::text::XTextContent
> & xTextContent
,
86 const sal_Bool bOutlineStyleAsNormalListStyle
,
87 const XMLTextListAutoStylePool
& rListAutoPool
,
88 // --> OD 2008-11-26 #158694#
89 const sal_Bool bExportTextNumberElement
)
93 // --> OD 2006-09-27 #i69627#
94 mbOutlineStyleAsNormalListStyle
= bOutlineStyleAsNormalListStyle
;
97 Reference
< XPropertySet
> xPropSet( xTextContent
, UNO_QUERY
);
98 Reference
< XPropertySetInfo
> xPropSetInfo
= xPropSet
->getPropertySetInfo();
100 // check if this paragraph supports a numbering
101 if( !xPropSetInfo
->hasPropertyByName( msNumberingLevel
) )
104 if( xPropSet
->getPropertyValue( msNumberingLevel
) >>= mnListLevel
)
106 if( xPropSetInfo
->hasPropertyByName( msNumberingRules
) )
108 xPropSet
->getPropertyValue( msNumberingRules
) >>= mxNumRules
;
113 // in applications using the outliner we always have a numbering rule,
114 // so a void property no numbering
118 // --> OD 2008-12-17 #i97312#
119 if ( mxNumRules
.is() && mxNumRules
->getCount() < 1 )
122 "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance does not contain any numbering rule" );
128 // --> OD 2006-09-27 #i69627#
129 bool bSuppressListStyle( false );
130 if ( mxNumRules
.is() )
132 if ( !mbOutlineStyleAsNormalListStyle
)
134 sal_Bool bIsOutline
= sal_False
;
135 Reference
<XPropertySet
> xNumRulesProps(mxNumRules
, UNO_QUERY
);
136 if ( xNumRulesProps
.is() &&
137 xNumRulesProps
->getPropertySetInfo()->
138 hasPropertyByName( msNumberingIsOutline
) )
140 xNumRulesProps
->getPropertyValue( msNumberingIsOutline
) >>= bIsOutline
;
141 bSuppressListStyle
= bIsOutline
? true : false;
146 if( mxNumRules
.is() && !bSuppressListStyle
)
149 // First try to find the numbering rules in the list auto style pool.
150 // If not found, the numbering rules instance has to be named.
151 msNumRulesName
= rListAutoPool
.Find( mxNumRules
);
152 if ( msNumRulesName
.getLength() == 0 )
154 Reference
< XNamed
> xNamed( mxNumRules
, UNO_QUERY
);
155 DBG_ASSERT( xNamed
.is(),
156 "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance have to be named. Serious defect -> please inform OD." );
159 msNumRulesName
= xNamed
->getName();
162 DBG_ASSERT( msNumRulesName
.getLength() > 0,
163 "<XMLTextNumRuleInfo::Set(..)> - no name found for numbering rules instance. Serious defect -> please inform OD." );
165 if( xPropSetInfo
->hasPropertyByName( msPropNameListId
) )
167 xPropSet
->getPropertyValue( msPropNameListId
) >>= msListId
;
170 // --> OD 2008-11-26 #158694#
171 mbContinueingPreviousSubTree
= sal_False
;
172 if( xPropSetInfo
->hasPropertyByName( msContinueingPreviousSubTree
) )
174 xPropSet
->getPropertyValue( msContinueingPreviousSubTree
) >>= mbContinueingPreviousSubTree
;
178 mbIsNumbered
= sal_True
;
179 if( xPropSetInfo
->hasPropertyByName( msNumberingIsNumber
) )
181 if( !(xPropSet
->getPropertyValue( msNumberingIsNumber
) >>= mbIsNumbered
) )
183 OSL_ENSURE( false, "numbered paragraph without number info" );
184 mbIsNumbered
= sal_False
;
190 if( xPropSetInfo
->hasPropertyByName( msParaIsNumberingRestart
) )
192 xPropSet
->getPropertyValue( msParaIsNumberingRestart
) >>= mbIsRestart
;
194 if( xPropSetInfo
->hasPropertyByName( msNumberingStartValue
) )
196 xPropSet
->getPropertyValue( msNumberingStartValue
) >>= mnListStartValue
;
200 OSL_ENSURE( mnListLevel
< mxNumRules
->getCount(), "wrong num rule level" );
201 if( mnListLevel
>= mxNumRules
->getCount() )
207 Sequence
<PropertyValue
> aProps
;
208 mxNumRules
->getByIndex( mnListLevel
) >>= aProps
;
210 const PropertyValue
* pPropArray
= aProps
.getConstArray();
211 sal_Int32 nCount
= aProps
.getLength();
212 for( sal_Int32 i
=0; i
<nCount
; i
++ )
214 const PropertyValue
& rProp
= pPropArray
[i
];
216 if ( rProp
.Name
== msPropNameStartWith
)
217 rProp
.Value
>>= mnListLevelStartValue
;
218 else if ( rProp
.Name
== msNumberingType
)
219 rProp
.Value
>>= mnNumberingType
;
222 // --> OD 2008-11-26 #158694#
223 msListLabelString
= ::rtl::OUString();
224 if ( bExportTextNumberElement
&&
225 xPropSetInfo
->hasPropertyByName( msListLabelStringProp
) )
227 xPropSet
->getPropertyValue( msListLabelStringProp
) >>= msListLabelString
;
231 // paragraph's list level range is [0..9] representing list levels [1..10]
240 static inline bool IsNumbering(sal_Int16 nType
)
242 return nType
!= NumberingType::CHAR_SPECIAL
&& nType
!= NumberingType::BITMAP
;
245 sal_Bool
XMLTextNumRuleInfo::BelongsToSameList( const XMLTextNumRuleInfo
& rCmp
, bool bIgnoreFormatting
) const
247 // Currently only the text documents support <ListId>.
248 if ( rCmp
.msListId
.getLength() > 0 ||
249 msListId
.getLength() > 0 )
251 return rCmp
.msListId
== msListId
;
255 if ( !bIgnoreFormatting
)
257 return HasSameNumRules( rCmp
);
261 return IsNumbering(mnNumberingType
) == IsNumbering(rCmp
.mnNumberingType
);