LibreOffice Module xmloff (master) 1
XMLTextNumRuleInfo.cxx
Go to the documentation of this file.
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 <osl/diagnose.h>
22#include <sal/log.hxx>
23#include <com/sun/star/beans/XPropertySet.hpp>
24#include <com/sun/star/beans/XPropertyState.hpp>
25#include <com/sun/star/beans/PropertyValue.hpp>
26#include <com/sun/star/container/XIndexReplace.hpp>
27#include <com/sun/star/style/NumberingType.hpp>
28#include <com/sun/star/text/XTextContent.hpp>
29#include <com/sun/star/container/XNamed.hpp>
32
33
34using namespace ::com::sun::star::uno;
35using namespace ::com::sun::star::beans;
36using namespace ::com::sun::star::container;
37using namespace ::com::sun::star::style;
38
39// Complete refactoring of the class and enhancement of the class for lists.
41 : mbListIdIsDefault(false)
42 , mnListStartValue( -1 )
43 , mnListLevel( 0 )
44 , mbIsNumbered( false )
45 , mbIsRestart( false )
46 , mnListLevelStartValue( -1 )
47 , mbOutlineStyleAsNormalListStyle( false )
48{
49 Reset();
50}
51
52// Written OpenDocument file format doesn't fit to the created text document (#i69627#)
54 const css::uno::Reference < css::text::XTextContent > & xTextContent,
55 const bool bOutlineStyleAsNormalListStyle,
56 const XMLTextListAutoStylePool& rListAutoPool,
57 const bool bExportTextNumberElement )
58{
59 Reset();
60 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
61 mbOutlineStyleAsNormalListStyle = bOutlineStyleAsNormalListStyle;
62
63 Reference< XPropertySet > xPropSet( xTextContent, UNO_QUERY );
64 Reference<XPropertyState> xPropState(xTextContent, UNO_QUERY);
65 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
66
67 // check if this paragraph supports a numbering
68 if( !xPropSetInfo->hasPropertyByName( "NumberingLevel" ) )
69 return;
70
71 if( xPropSet->getPropertyValue( "NumberingLevel" ) >>= mnListLevel )
72 {
73 if( xPropSetInfo->hasPropertyByName( "NumberingRules" ) )
74 {
75 xPropSet->getPropertyValue( "NumberingRules" ) >>= mxNumRules;
76 }
77 }
78 else
79 {
80 // in applications using the outliner we always have a numbering rule,
81 // so a void property no numbering
82 mnListLevel = 0;
83 }
84
85 // Assertion saving writer document (#i97312#)
86 if ( mxNumRules.is() && mxNumRules->getCount() < 1 )
87 {
88 SAL_WARN("xmloff",
89 "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance does not contain any numbering rule" );
90 Reset();
91 return;
92 }
93
94 if ( mnListLevel < 0 )
95 {
96 SAL_WARN("xmloff",
97 "<XMLTextNumRuleInfo::Set(..)> - unexpected numbering level" );
98 Reset();
99 return;
100 }
101
102 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
103 bool bSuppressListStyle( false );
104 if ( mxNumRules.is() )
105 {
107 {
108 Reference<XPropertySet> xNumRulesProps(mxNumRules, UNO_QUERY);
109 if ( xNumRulesProps.is() &&
110 xNumRulesProps->getPropertySetInfo()->
111 hasPropertyByName( "NumberingIsOutline" ) )
112 {
113 bool bIsOutline = false;
114 xNumRulesProps->getPropertyValue( "NumberingIsOutline" ) >>= bIsOutline;
115 bSuppressListStyle = bIsOutline;
116 }
117 }
118 }
119
120 if( mxNumRules.is() && !bSuppressListStyle )
121 {
122 // First try to find the numbering rules in the list auto style pool.
123 // If not found, the numbering rules instance has to be named.
124 msNumRulesName = rListAutoPool.Find( mxNumRules );
125 if ( msNumRulesName.isEmpty() )
126 {
127 Reference < XNamed > xNamed( mxNumRules, UNO_QUERY );
128 SAL_WARN_IF( !xNamed.is(), "xmloff",
129 "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance have to be named. Serious defect." );
130 if( xNamed.is() )
131 {
132 msNumRulesName = xNamed->getName();
133 }
134 }
135 SAL_WARN_IF( msNumRulesName.isEmpty(), "xmloff",
136 "<XMLTextNumRuleInfo::Set(..)> - no name found for numbering rules instance. Serious defect." );
137
138 if( xPropSetInfo->hasPropertyByName( "ListId" ) )
139 {
140 xPropSet->getPropertyValue( "ListId" ) >>= msListId;
141
142 if (xPropState.is())
143 {
145 = xPropState->getPropertyState("ListId") == PropertyState_DEFAULT_VALUE;
146 }
147 }
148
150 if( xPropSetInfo->hasPropertyByName( "ContinueingPreviousSubTree" ) )
151 {
152 xPropSet->getPropertyValue( "ContinueingPreviousSubTree" ) >>= mbContinueingPreviousSubTree;
153 }
154
155 mbIsNumbered = true;
156 if( xPropSetInfo->hasPropertyByName( "NumberingIsNumber" ) )
157 {
158 if( !(xPropSet->getPropertyValue( "NumberingIsNumber" ) >>= mbIsNumbered ) )
159 {
160 OSL_FAIL( "numbered paragraph without number info" );
161 mbIsNumbered = false;
162 }
163 }
164
165 if( mbIsNumbered )
166 {
167 if( xPropSetInfo->hasPropertyByName( "ParaIsNumberingRestart" ) )
168 {
169 xPropSet->getPropertyValue( "ParaIsNumberingRestart" ) >>= mbIsRestart;
170 }
171 if( xPropSetInfo->hasPropertyByName( "NumberingStartValue" ) )
172 {
173 xPropSet->getPropertyValue( "NumberingStartValue" ) >>= mnListStartValue;
174 }
175 }
176
177 OSL_ENSURE( mnListLevel < mxNumRules->getCount(), "wrong num rule level" );
178 if( mnListLevel >= mxNumRules->getCount() )
179 {
180 Reset();
181 return;
182 }
183
184 Sequence<PropertyValue> aProps;
185 mxNumRules->getByIndex( mnListLevel ) >>= aProps;
186
187 auto pProp = std::find_if(std::cbegin(aProps), std::cend(aProps),
188 [](const PropertyValue& rProp) { return rProp.Name == "StartWith"; });
189 if (pProp != std::cend(aProps))
190 {
191 pProp->Value >>= mnListLevelStartValue;
192 }
193
194 msListLabelString.clear();
195 if ( bExportTextNumberElement &&
196 xPropSetInfo->hasPropertyByName( "ListLabelString" ) )
197 {
198 xPropSet->getPropertyValue( "ListLabelString" ) >>= msListLabelString;
199 }
200
201 // paragraph's list level range is [0..9] representing list levels [1..10]
202 ++mnListLevel;
203 }
204 else
205 {
206 mnListLevel = 0;
207 }
208}
209
211{
212 bool bRet( true );
213 // Currently only the text documents support <ListId>.
214 if ( !rCmp.msListId.isEmpty() || !msListId.isEmpty() )
215 {
216 bRet = rCmp.msListId == msListId;
217 }
218 else
219 {
220 bRet = rCmp.msNumRulesName == msNumRulesName;
221 }
222
223 return bRet;
224}
225
226/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPRIVATE sal_uInt32 Find(const XMLTextListAutoStylePoolEntry_Impl *pEntry) const
information about list and list style for a certain paragraph
bool mbListIdIsDefault
msListId won't be referenced by later lists.
void Set(const css::uno::Reference< css::text::XTextContent > &rTextContent, const bool bOutlineStyleAsNormalListStyle, const XMLTextListAutoStylePool &rListAutoPool, const bool bExportTextNumberElement)
css::uno::Reference< css::container::XIndexReplace > mxNumRules
bool BelongsToSameList(const XMLTextNumRuleInfo &rCmp) const
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)