Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <tools/debug.hxx>
22 : #include <com/sun/star/beans/XPropertySet.hpp>
23 : #include <com/sun/star/beans/PropertyValue.hpp>
24 : #include <com/sun/star/container/XIndexReplace.hpp>
25 : #include <com/sun/star/style/NumberingType.hpp>
26 : #include <com/sun/star/container/XNamed.hpp>
27 : #include "XMLTextNumRuleInfo.hxx"
28 : #include "xmloff/XMLTextListAutoStylePool.hxx"
29 :
30 : using ::rtl::OUString;
31 :
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;
36 :
37 : // Complete refactoring of the class and enhancement of the class for lists.
38 174 : XMLTextNumRuleInfo::XMLTextNumRuleInfo()
39 : : msNumberingRules(RTL_CONSTASCII_USTRINGPARAM("NumberingRules"))
40 : , msNumberingLevel(RTL_CONSTASCII_USTRINGPARAM("NumberingLevel"))
41 : , msNumberingStartValue(RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue"))
42 : , msParaIsNumberingRestart(RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart"))
43 : , msNumberingIsNumber(RTL_CONSTASCII_USTRINGPARAM("NumberingIsNumber"))
44 : , msNumberingIsOutline(RTL_CONSTASCII_USTRINGPARAM("NumberingIsOutline"))
45 : , msPropNameListId(RTL_CONSTASCII_USTRINGPARAM("ListId"))
46 : , msPropNameStartWith(RTL_CONSTASCII_USTRINGPARAM("StartWith"))
47 : , msContinueingPreviousSubTree(RTL_CONSTASCII_USTRINGPARAM("ContinueingPreviousSubTree"))
48 : , msListLabelStringProp(RTL_CONSTASCII_USTRINGPARAM("ListLabelString"))
49 : , mxNumRules()
50 : , msNumRulesName()
51 : , msListId()
52 : , mnListStartValue( -1 )
53 : , mnListLevel( 0 )
54 : , mbIsNumbered( sal_False )
55 : , mbIsRestart( sal_False )
56 : , mnListLevelStartValue( -1 )
57 174 : , mbOutlineStyleAsNormalListStyle( sal_False )
58 : {
59 174 : Reset();
60 174 : }
61 :
62 : // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
63 30 : void XMLTextNumRuleInfo::Set(
64 : const ::com::sun::star::uno::Reference <
65 : ::com::sun::star::text::XTextContent > & xTextContent,
66 : const sal_Bool bOutlineStyleAsNormalListStyle,
67 : const XMLTextListAutoStylePool& rListAutoPool,
68 : const sal_Bool bExportTextNumberElement )
69 : {
70 30 : Reset();
71 : // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
72 30 : mbOutlineStyleAsNormalListStyle = bOutlineStyleAsNormalListStyle;
73 :
74 30 : Reference< XPropertySet > xPropSet( xTextContent, UNO_QUERY );
75 30 : Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
76 :
77 : // check if this paragraph supports a numbering
78 30 : if( !xPropSetInfo->hasPropertyByName( msNumberingLevel ) )
79 : return;
80 :
81 20 : if( xPropSet->getPropertyValue( msNumberingLevel ) >>= mnListLevel )
82 : {
83 20 : if( xPropSetInfo->hasPropertyByName( msNumberingRules ) )
84 : {
85 20 : xPropSet->getPropertyValue( msNumberingRules ) >>= mxNumRules;
86 : }
87 : }
88 : else
89 : {
90 : // in applications using the outliner we always have a numbering rule,
91 : // so a void property no numbering
92 0 : mnListLevel = 0;
93 : }
94 :
95 : // Assertion saving writer document (#i97312#)
96 20 : if ( mxNumRules.is() && mxNumRules->getCount() < 1 )
97 : {
98 : DBG_ASSERT( false,
99 : "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance does not contain any numbering rule" );
100 1 : Reset();
101 : return;
102 : }
103 :
104 19 : if ( mnListLevel < 0 )
105 : {
106 : DBG_ASSERT( false,
107 : "<XMLTextNumRuleInfo::Set(..)> - unexpected numbering level" );
108 0 : Reset();
109 : return;
110 : }
111 :
112 : // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
113 19 : bool bSuppressListStyle( false );
114 19 : if ( mxNumRules.is() )
115 : {
116 0 : if ( !mbOutlineStyleAsNormalListStyle )
117 : {
118 0 : sal_Bool bIsOutline = sal_False;
119 0 : Reference<XPropertySet> xNumRulesProps(mxNumRules, UNO_QUERY);
120 0 : if ( xNumRulesProps.is() &&
121 0 : xNumRulesProps->getPropertySetInfo()->
122 0 : hasPropertyByName( msNumberingIsOutline ) )
123 : {
124 0 : xNumRulesProps->getPropertyValue( msNumberingIsOutline ) >>= bIsOutline;
125 0 : bSuppressListStyle = bIsOutline ? true : false;
126 0 : }
127 : }
128 : }
129 :
130 19 : if( mxNumRules.is() && !bSuppressListStyle )
131 : {
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 0 : msNumRulesName = rListAutoPool.Find( mxNumRules );
135 0 : if ( msNumRulesName.isEmpty() )
136 : {
137 0 : 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 0 : if( xNamed.is() )
141 : {
142 0 : msNumRulesName = xNamed->getName();
143 0 : }
144 : }
145 : DBG_ASSERT( !msNumRulesName.isEmpty(),
146 : "<XMLTextNumRuleInfo::Set(..)> - no name found for numbering rules instance. Serious defect -> please inform OD." );
147 :
148 0 : if( xPropSetInfo->hasPropertyByName( msPropNameListId ) )
149 : {
150 0 : xPropSet->getPropertyValue( msPropNameListId ) >>= msListId;
151 : }
152 :
153 0 : mbContinueingPreviousSubTree = sal_False;
154 0 : if( xPropSetInfo->hasPropertyByName( msContinueingPreviousSubTree ) )
155 : {
156 0 : xPropSet->getPropertyValue( msContinueingPreviousSubTree ) >>= mbContinueingPreviousSubTree;
157 : }
158 :
159 0 : mbIsNumbered = sal_True;
160 0 : if( xPropSetInfo->hasPropertyByName( msNumberingIsNumber ) )
161 : {
162 0 : if( !(xPropSet->getPropertyValue( msNumberingIsNumber ) >>= mbIsNumbered ) )
163 : {
164 : OSL_FAIL( "numbered paragraph without number info" );
165 0 : mbIsNumbered = sal_False;
166 : }
167 : }
168 :
169 0 : if( mbIsNumbered )
170 : {
171 0 : if( xPropSetInfo->hasPropertyByName( msParaIsNumberingRestart ) )
172 : {
173 0 : xPropSet->getPropertyValue( msParaIsNumberingRestart ) >>= mbIsRestart;
174 : }
175 0 : if( xPropSetInfo->hasPropertyByName( msNumberingStartValue ) )
176 : {
177 0 : xPropSet->getPropertyValue( msNumberingStartValue ) >>= mnListStartValue;
178 : }
179 : }
180 :
181 : OSL_ENSURE( mnListLevel < mxNumRules->getCount(), "wrong num rule level" );
182 0 : if( mnListLevel >= mxNumRules->getCount() )
183 : {
184 0 : Reset();
185 : return;
186 : }
187 :
188 0 : Sequence<PropertyValue> aProps;
189 0 : mxNumRules->getByIndex( mnListLevel ) >>= aProps;
190 :
191 0 : const PropertyValue* pPropArray = aProps.getConstArray();
192 0 : sal_Int32 nCount = aProps.getLength();
193 0 : for( sal_Int32 i=0; i<nCount; i++ )
194 : {
195 0 : const PropertyValue& rProp = pPropArray[i];
196 :
197 0 : if ( rProp.Name == msPropNameStartWith )
198 : {
199 0 : rProp.Value >>= mnListLevelStartValue;
200 0 : break;
201 : }
202 : }
203 :
204 0 : msListLabelString = ::rtl::OUString();
205 0 : if ( bExportTextNumberElement &&
206 0 : xPropSetInfo->hasPropertyByName( msListLabelStringProp ) )
207 : {
208 0 : xPropSet->getPropertyValue( msListLabelStringProp ) >>= msListLabelString;
209 : }
210 :
211 : // paragraph's list level range is [0..9] representing list levels [1..10]
212 0 : ++mnListLevel;
213 : }
214 : else
215 : {
216 19 : mnListLevel = 0;
217 30 : }
218 : }
219 :
220 0 : sal_Bool XMLTextNumRuleInfo::BelongsToSameList( const XMLTextNumRuleInfo& rCmp ) const
221 : {
222 0 : sal_Bool bRet( sal_True );
223 : // Currently only the text documents support <ListId>.
224 0 : if ( !rCmp.msListId.isEmpty() || !msListId.isEmpty() )
225 : {
226 0 : bRet = rCmp.msListId == msListId;
227 : }
228 : else
229 : {
230 0 : bRet = HasSameNumRules( rCmp );
231 : }
232 :
233 0 : return bRet;
234 : }
235 :
236 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|