bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / XMLTextNumRuleInfo.cxx
blobcb597daf167fac1b96febf064a234e2e946075fc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <tools/debug.hxx>
22 #include <osl/diagnose.h>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/container/XIndexReplace.hpp>
26 #include <com/sun/star/style/NumberingType.hpp>
27 #include <com/sun/star/container/XNamed.hpp>
28 #include "XMLTextNumRuleInfo.hxx"
29 #include <xmloff/XMLTextListAutoStylePool.hxx>
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::beans;
34 using namespace ::com::sun::star::container;
35 using namespace ::com::sun::star::style;
37 // Complete refactoring of the class and enhancement of the class for lists.
38 XMLTextNumRuleInfo::XMLTextNumRuleInfo()
39 : msNumberingRules("NumberingRules")
40 , msNumberingLevel("NumberingLevel")
41 , msNumberingStartValue("NumberingStartValue")
42 , msParaIsNumberingRestart("ParaIsNumberingRestart")
43 , msNumberingIsNumber("NumberingIsNumber")
44 , msNumberingIsOutline("NumberingIsOutline")
45 , msPropNameListId("ListId")
46 , msPropNameStartWith("StartWith")
47 , msContinueingPreviousSubTree("ContinueingPreviousSubTree")
48 , msListLabelStringProp("ListLabelString")
49 , mxNumRules()
50 , msNumRulesName()
51 , msListId()
52 , mnListStartValue( -1 )
53 , mnListLevel( 0 )
54 , mbIsNumbered( false )
55 , mbIsRestart( false )
56 , mnListLevelStartValue( -1 )
57 , mbOutlineStyleAsNormalListStyle( false )
59 Reset();
62 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
63 void XMLTextNumRuleInfo::Set(
64 const ::com::sun::star::uno::Reference <
65 ::com::sun::star::text::XTextContent > & xTextContent,
66 const bool bOutlineStyleAsNormalListStyle,
67 const XMLTextListAutoStylePool& rListAutoPool,
68 const bool bExportTextNumberElement )
70 Reset();
71 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
72 mbOutlineStyleAsNormalListStyle = bOutlineStyleAsNormalListStyle;
74 Reference< XPropertySet > xPropSet( xTextContent, UNO_QUERY );
75 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
77 // check if this paragraph supports a numbering
78 if( !xPropSetInfo->hasPropertyByName( msNumberingLevel ) )
79 return;
81 if( xPropSet->getPropertyValue( msNumberingLevel ) >>= mnListLevel )
83 if( xPropSetInfo->hasPropertyByName( msNumberingRules ) )
85 xPropSet->getPropertyValue( msNumberingRules ) >>= mxNumRules;
88 else
90 // in applications using the outliner we always have a numbering rule,
91 // so a void property no numbering
92 mnListLevel = 0;
95 // Assertion saving writer document (#i97312#)
96 if ( mxNumRules.is() && mxNumRules->getCount() < 1 )
98 DBG_ASSERT( false,
99 "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance does not contain any numbering rule" );
100 Reset();
101 return;
104 if ( mnListLevel < 0 )
106 DBG_ASSERT( false,
107 "<XMLTextNumRuleInfo::Set(..)> - unexpected numbering level" );
108 Reset();
109 return;
112 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
113 bool bSuppressListStyle( false );
114 if ( mxNumRules.is() )
116 if ( !mbOutlineStyleAsNormalListStyle )
118 Reference<XPropertySet> xNumRulesProps(mxNumRules, UNO_QUERY);
119 if ( xNumRulesProps.is() &&
120 xNumRulesProps->getPropertySetInfo()->
121 hasPropertyByName( msNumberingIsOutline ) )
123 bool bIsOutline = false;
124 xNumRulesProps->getPropertyValue( msNumberingIsOutline ) >>= bIsOutline;
125 bSuppressListStyle = bIsOutline;
130 if( mxNumRules.is() && !bSuppressListStyle )
132 // First try to find the numbering rules in the list auto style pool.
133 // If not found, the numbering rules instance has to be named.
134 msNumRulesName = rListAutoPool.Find( mxNumRules );
135 if ( msNumRulesName.isEmpty() )
137 Reference < XNamed > xNamed( mxNumRules, UNO_QUERY );
138 DBG_ASSERT( xNamed.is(),
139 "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance have to be named. Serious defect -> please inform OD." );
140 if( xNamed.is() )
142 msNumRulesName = xNamed->getName();
145 DBG_ASSERT( !msNumRulesName.isEmpty(),
146 "<XMLTextNumRuleInfo::Set(..)> - no name found for numbering rules instance. Serious defect -> please inform OD." );
148 if( xPropSetInfo->hasPropertyByName( msPropNameListId ) )
150 xPropSet->getPropertyValue( msPropNameListId ) >>= msListId;
153 mbContinueingPreviousSubTree = false;
154 if( xPropSetInfo->hasPropertyByName( msContinueingPreviousSubTree ) )
156 xPropSet->getPropertyValue( msContinueingPreviousSubTree ) >>= mbContinueingPreviousSubTree;
159 mbIsNumbered = true;
160 if( xPropSetInfo->hasPropertyByName( msNumberingIsNumber ) )
162 if( !(xPropSet->getPropertyValue( msNumberingIsNumber ) >>= mbIsNumbered ) )
164 OSL_FAIL( "numbered paragraph without number info" );
165 mbIsNumbered = false;
169 if( mbIsNumbered )
171 if( xPropSetInfo->hasPropertyByName( msParaIsNumberingRestart ) )
173 xPropSet->getPropertyValue( msParaIsNumberingRestart ) >>= mbIsRestart;
175 if( xPropSetInfo->hasPropertyByName( msNumberingStartValue ) )
177 xPropSet->getPropertyValue( msNumberingStartValue ) >>= mnListStartValue;
181 OSL_ENSURE( mnListLevel < mxNumRules->getCount(), "wrong num rule level" );
182 if( mnListLevel >= mxNumRules->getCount() )
184 Reset();
185 return;
188 Sequence<PropertyValue> aProps;
189 mxNumRules->getByIndex( mnListLevel ) >>= aProps;
191 const PropertyValue* pPropArray = aProps.getConstArray();
192 sal_Int32 nCount = aProps.getLength();
193 for( sal_Int32 i=0; i<nCount; i++ )
195 const PropertyValue& rProp = pPropArray[i];
197 if ( rProp.Name == msPropNameStartWith )
199 rProp.Value >>= mnListLevelStartValue;
200 break;
204 msListLabelString.clear();
205 if ( bExportTextNumberElement &&
206 xPropSetInfo->hasPropertyByName( msListLabelStringProp ) )
208 xPropSet->getPropertyValue( msListLabelStringProp ) >>= msListLabelString;
211 // paragraph's list level range is [0..9] representing list levels [1..10]
212 ++mnListLevel;
214 else
216 mnListLevel = 0;
220 bool XMLTextNumRuleInfo::BelongsToSameList( const XMLTextNumRuleInfo& rCmp ) const
222 bool bRet( true );
223 // Currently only the text documents support <ListId>.
224 if ( !rCmp.msListId.isEmpty() || !msListId.isEmpty() )
226 bRet = rCmp.msListId == msListId;
228 else
230 bRet = HasSameNumRules( rCmp );
233 return bRet;
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */