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