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