1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <tools/debug.hxx>
28cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
29cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
30cdf0e10cSrcweir #include <com/sun/star/container/XIndexReplace.hpp>
31cdf0e10cSrcweir #include <com/sun/star/style/NumberingType.hpp>
32cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
33cdf0e10cSrcweir #include "XMLTextNumRuleInfo.hxx"
34cdf0e10cSrcweir // --> OD 2008-04-25 #refactorlists#
35cdf0e10cSrcweir #include "xmloff/XMLTextListAutoStylePool.hxx"
36cdf0e10cSrcweir // <--
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using ::rtl::OUString;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace ::com::sun::star::uno;
41cdf0e10cSrcweir using namespace ::com::sun::star::beans;
42cdf0e10cSrcweir using namespace ::com::sun::star::container;
43cdf0e10cSrcweir using namespace ::com::sun::star::style;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir // --> OD 2008-05-08 #refactorlists#
46cdf0e10cSrcweir // Complete refactoring of the class and enhancement of the class for lists.
XMLTextNumRuleInfo()47cdf0e10cSrcweir XMLTextNumRuleInfo::XMLTextNumRuleInfo()
48cdf0e10cSrcweir     : msNumberingRules(RTL_CONSTASCII_USTRINGPARAM("NumberingRules"))
49cdf0e10cSrcweir     , msNumberingLevel(RTL_CONSTASCII_USTRINGPARAM("NumberingLevel"))
50cdf0e10cSrcweir     , msNumberingStartValue(RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue"))
51cdf0e10cSrcweir     , msParaIsNumberingRestart(RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart"))
52cdf0e10cSrcweir     , msNumberingIsNumber(RTL_CONSTASCII_USTRINGPARAM("NumberingIsNumber"))
53cdf0e10cSrcweir     , msNumberingIsOutline(RTL_CONSTASCII_USTRINGPARAM("NumberingIsOutline"))
54cdf0e10cSrcweir     , msPropNameListId(RTL_CONSTASCII_USTRINGPARAM("ListId"))
55cdf0e10cSrcweir     , msPropNameStartWith(RTL_CONSTASCII_USTRINGPARAM("StartWith"))
56cdf0e10cSrcweir     // --> OD 2008-11-26 #158694#
57cdf0e10cSrcweir     , msContinueingPreviousSubTree(RTL_CONSTASCII_USTRINGPARAM("ContinueingPreviousSubTree"))
58cdf0e10cSrcweir     , msListLabelStringProp(RTL_CONSTASCII_USTRINGPARAM("ListLabelString"))
59cdf0e10cSrcweir     // <--
60cdf0e10cSrcweir     , mxNumRules()
61cdf0e10cSrcweir     , msNumRulesName()
62cdf0e10cSrcweir     , msListId()
63cdf0e10cSrcweir     , mnListStartValue( -1 )
64cdf0e10cSrcweir     , mnListLevel( 0 )
65cdf0e10cSrcweir     , mbIsNumbered( sal_False )
66cdf0e10cSrcweir     , mbIsRestart( sal_False )
67cdf0e10cSrcweir     , mnListLevelStartValue( -1 )
68cdf0e10cSrcweir     , mbOutlineStyleAsNormalListStyle( sal_False )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	Reset();
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // --> OD 2006-09-27 #i69627#
Set(const::com::sun::star::uno::Reference<::com::sun::star::text::XTextContent> & xTextContent,const sal_Bool bOutlineStyleAsNormalListStyle,const XMLTextListAutoStylePool & rListAutoPool,const sal_Bool bExportTextNumberElement)74cdf0e10cSrcweir void XMLTextNumRuleInfo::Set(
75cdf0e10cSrcweir         const ::com::sun::star::uno::Reference <
76cdf0e10cSrcweir                         ::com::sun::star::text::XTextContent > & xTextContent,
77cdf0e10cSrcweir         const sal_Bool bOutlineStyleAsNormalListStyle,
78cdf0e10cSrcweir         const XMLTextListAutoStylePool& rListAutoPool,
79cdf0e10cSrcweir         // --> OD 2008-11-26 #158694#
80cdf0e10cSrcweir         const sal_Bool bExportTextNumberElement )
81cdf0e10cSrcweir         // <--
82cdf0e10cSrcweir {
83cdf0e10cSrcweir 	Reset();
84cdf0e10cSrcweir     // --> OD 2006-09-27 #i69627#
85cdf0e10cSrcweir     mbOutlineStyleAsNormalListStyle = bOutlineStyleAsNormalListStyle;
86cdf0e10cSrcweir     // <--
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	Reference< XPropertySet > xPropSet( xTextContent, UNO_QUERY );
89cdf0e10cSrcweir 	Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     // check if this paragraph supports a numbering
92cdf0e10cSrcweir     if( !xPropSetInfo->hasPropertyByName( msNumberingLevel ) )
93cdf0e10cSrcweir 		return;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     if( xPropSet->getPropertyValue( msNumberingLevel ) >>= mnListLevel )
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir         if( xPropSetInfo->hasPropertyByName( msNumberingRules ) )
98cdf0e10cSrcweir         {
99cdf0e10cSrcweir             xPropSet->getPropertyValue( msNumberingRules ) >>= mxNumRules;
100cdf0e10cSrcweir         }
101cdf0e10cSrcweir 	}
102cdf0e10cSrcweir 	else
103cdf0e10cSrcweir 	{
104cdf0e10cSrcweir 		// in applications using the outliner we always have a numbering rule,
105cdf0e10cSrcweir 		// so a void property no numbering
106cdf0e10cSrcweir         mnListLevel = 0;
107cdf0e10cSrcweir 	}
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     // --> OD 2008-12-17 #i97312#
110cdf0e10cSrcweir     if ( mxNumRules.is() && mxNumRules->getCount() < 1 )
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         DBG_ASSERT( false,
113cdf0e10cSrcweir                     "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance does not contain any numbering rule" );
114cdf0e10cSrcweir         Reset();
115cdf0e10cSrcweir         return;
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir     // <--
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     // --> OD 2010-01-13 #b6912256#
120cdf0e10cSrcweir     if ( mnListLevel < 0 )
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         DBG_ASSERT( false,
123cdf0e10cSrcweir                     "<XMLTextNumRuleInfo::Set(..)> - unexpected numbering level" );
124cdf0e10cSrcweir         Reset();
125cdf0e10cSrcweir         return;
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     // --> OD 2006-09-27 #i69627#
129cdf0e10cSrcweir     bool bSuppressListStyle( false );
130cdf0e10cSrcweir     if ( mxNumRules.is() )
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir         if ( !mbOutlineStyleAsNormalListStyle )
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir             sal_Bool bIsOutline = sal_False;
135cdf0e10cSrcweir             Reference<XPropertySet> xNumRulesProps(mxNumRules, UNO_QUERY);
136cdf0e10cSrcweir             if ( xNumRulesProps.is() &&
137cdf0e10cSrcweir                  xNumRulesProps->getPropertySetInfo()->
138cdf0e10cSrcweir                                     hasPropertyByName( msNumberingIsOutline ) )
139cdf0e10cSrcweir             {
140cdf0e10cSrcweir                 xNumRulesProps->getPropertyValue( msNumberingIsOutline ) >>= bIsOutline;
141cdf0e10cSrcweir                 bSuppressListStyle = bIsOutline ? true : false;
142cdf0e10cSrcweir             }
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     if( mxNumRules.is() && !bSuppressListStyle )
147cdf0e10cSrcweir     // <--
148cdf0e10cSrcweir 	{
149cdf0e10cSrcweir         // First try to find the numbering rules in the list auto style pool.
150cdf0e10cSrcweir         // If not found, the numbering rules instance has to be named.
151cdf0e10cSrcweir         msNumRulesName = rListAutoPool.Find( mxNumRules );
152cdf0e10cSrcweir         if ( msNumRulesName.getLength() == 0 )
153cdf0e10cSrcweir         {
154cdf0e10cSrcweir             Reference < XNamed > xNamed( mxNumRules, UNO_QUERY );
155cdf0e10cSrcweir             DBG_ASSERT( xNamed.is(),
156cdf0e10cSrcweir                         "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance have to be named. Serious defect -> please inform OD." );
157cdf0e10cSrcweir             if( xNamed.is() )
158cdf0e10cSrcweir             {
159cdf0e10cSrcweir                 msNumRulesName = xNamed->getName();
160cdf0e10cSrcweir             }
161cdf0e10cSrcweir         }
162cdf0e10cSrcweir         DBG_ASSERT( msNumRulesName.getLength() > 0,
163cdf0e10cSrcweir                     "<XMLTextNumRuleInfo::Set(..)> - no name found for numbering rules instance. Serious defect -> please inform OD." );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         if( xPropSetInfo->hasPropertyByName( msPropNameListId ) )
166cdf0e10cSrcweir         {
167cdf0e10cSrcweir             xPropSet->getPropertyValue( msPropNameListId ) >>= msListId;
168cdf0e10cSrcweir         }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir         // --> OD 2008-11-26 #158694#
171cdf0e10cSrcweir         mbContinueingPreviousSubTree = sal_False;
172cdf0e10cSrcweir         if( xPropSetInfo->hasPropertyByName( msContinueingPreviousSubTree ) )
173cdf0e10cSrcweir         {
174cdf0e10cSrcweir             xPropSet->getPropertyValue( msContinueingPreviousSubTree ) >>= mbContinueingPreviousSubTree;
175cdf0e10cSrcweir         }
176cdf0e10cSrcweir         // <--
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         mbIsNumbered = sal_True;
179cdf0e10cSrcweir         if( xPropSetInfo->hasPropertyByName( msNumberingIsNumber ) )
180cdf0e10cSrcweir 		{
181cdf0e10cSrcweir             if( !(xPropSet->getPropertyValue( msNumberingIsNumber ) >>= mbIsNumbered ) )
182cdf0e10cSrcweir             {
183cdf0e10cSrcweir     			OSL_ENSURE( false, "numbered paragraph without number info" );
184cdf0e10cSrcweir                 mbIsNumbered = sal_False;
185cdf0e10cSrcweir             }
186cdf0e10cSrcweir 		}
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         if( mbIsNumbered )
189cdf0e10cSrcweir 		{
190cdf0e10cSrcweir             if( xPropSetInfo->hasPropertyByName( msParaIsNumberingRestart ) )
191cdf0e10cSrcweir 			{
192cdf0e10cSrcweir                 xPropSet->getPropertyValue( msParaIsNumberingRestart ) >>= mbIsRestart;
193cdf0e10cSrcweir 			}
194cdf0e10cSrcweir             if( xPropSetInfo->hasPropertyByName( msNumberingStartValue ) )
195cdf0e10cSrcweir 			{
196cdf0e10cSrcweir                 xPropSet->getPropertyValue( msNumberingStartValue ) >>= mnListStartValue;
197cdf0e10cSrcweir 			}
198cdf0e10cSrcweir 		}
199cdf0e10cSrcweir 
200cdf0e10cSrcweir         OSL_ENSURE( mnListLevel < mxNumRules->getCount(), "wrong num rule level" );
201cdf0e10cSrcweir         if( mnListLevel >= mxNumRules->getCount() )
202cdf0e10cSrcweir 		{
203cdf0e10cSrcweir 			Reset();
204cdf0e10cSrcweir 			return;
205cdf0e10cSrcweir 		}
206cdf0e10cSrcweir 
207cdf0e10cSrcweir         Sequence<PropertyValue> aProps;
208cdf0e10cSrcweir         mxNumRules->getByIndex( mnListLevel ) >>= aProps;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         const PropertyValue* pPropArray = aProps.getConstArray();
211cdf0e10cSrcweir         sal_Int32 nCount = aProps.getLength();
212cdf0e10cSrcweir         for( sal_Int32 i=0; i<nCount; i++ )
213cdf0e10cSrcweir         {
214cdf0e10cSrcweir           const PropertyValue& rProp = pPropArray[i];
215cdf0e10cSrcweir 
216cdf0e10cSrcweir             if ( rProp.Name == msPropNameStartWith )
217cdf0e10cSrcweir             {
218cdf0e10cSrcweir                 rProp.Value >>= mnListLevelStartValue;
219cdf0e10cSrcweir                 break;
220cdf0e10cSrcweir             }
221cdf0e10cSrcweir         }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         // --> OD 2008-11-26 #158694#
224cdf0e10cSrcweir         msListLabelString = ::rtl::OUString();
225cdf0e10cSrcweir         if ( bExportTextNumberElement &&
226cdf0e10cSrcweir              xPropSetInfo->hasPropertyByName( msListLabelStringProp ) )
227cdf0e10cSrcweir         {
228cdf0e10cSrcweir             xPropSet->getPropertyValue( msListLabelStringProp ) >>= msListLabelString;
229cdf0e10cSrcweir         }
230cdf0e10cSrcweir         // <--
231cdf0e10cSrcweir 
232cdf0e10cSrcweir         // paragraph's list level range is [0..9] representing list levels [1..10]
233cdf0e10cSrcweir         ++mnListLevel;
234cdf0e10cSrcweir 	}
235cdf0e10cSrcweir     else
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir         mnListLevel = 0;
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
BelongsToSameList(const XMLTextNumRuleInfo & rCmp) const241cdf0e10cSrcweir sal_Bool XMLTextNumRuleInfo::BelongsToSameList( const XMLTextNumRuleInfo& rCmp ) const
242cdf0e10cSrcweir {
243cdf0e10cSrcweir     sal_Bool bRet( sal_True );
244cdf0e10cSrcweir     // Currently only the text documents support <ListId>.
245cdf0e10cSrcweir     if ( rCmp.msListId.getLength() > 0 ||
246cdf0e10cSrcweir          msListId.getLength() > 0 )
247cdf0e10cSrcweir     {
248cdf0e10cSrcweir         bRet = rCmp.msListId == msListId;
249cdf0e10cSrcweir     }
250cdf0e10cSrcweir     else
251cdf0e10cSrcweir     {
252cdf0e10cSrcweir         bRet = HasSameNumRules( rCmp );
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir     return bRet;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir // <--
258