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 const bool bListIdIsDefault )
59{
60 Reset();
61 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
62 mbOutlineStyleAsNormalListStyle = bOutlineStyleAsNormalListStyle;
63
64 Reference< XPropertySet > xPropSet( 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
143 mbListIdIsDefault = bListIdIsDefault;
144
146 if( xPropSetInfo->hasPropertyByName( "ContinueingPreviousSubTree" ) )
147 {
148 xPropSet->getPropertyValue( "ContinueingPreviousSubTree" ) >>= mbContinueingPreviousSubTree;
149 }
150
151 mbIsNumbered = true;
152 if( xPropSetInfo->hasPropertyByName( "NumberingIsNumber" ) )
153 {
154 if( !(xPropSet->getPropertyValue( "NumberingIsNumber" ) >>= mbIsNumbered ) )
155 {
156 OSL_FAIL( "numbered paragraph without number info" );
157 mbIsNumbered = false;
158 }
159 }
160
161 if( mbIsNumbered )
162 {
163 if( xPropSetInfo->hasPropertyByName( "ParaIsNumberingRestart" ) )
164 {
165 xPropSet->getPropertyValue( "ParaIsNumberingRestart" ) >>= mbIsRestart;
166 }
167 if( xPropSetInfo->hasPropertyByName( "NumberingStartValue" ) )
168 {
169 xPropSet->getPropertyValue( "NumberingStartValue" ) >>= mnListStartValue;
170 }
171 }
172
173 OSL_ENSURE( mnListLevel < mxNumRules->getCount(), "wrong num rule level" );
174 if( mnListLevel >= mxNumRules->getCount() )
175 {
176 Reset();
177 return;
178 }
179
180 Sequence<PropertyValue> aProps;
181 mxNumRules->getByIndex( mnListLevel ) >>= aProps;
182
183 auto pProp = std::find_if(std::cbegin(aProps), std::cend(aProps),
184 [](const PropertyValue& rProp) { return rProp.Name == "StartWith"; });
185 if (pProp != std::cend(aProps))
186 {
187 pProp->Value >>= mnListLevelStartValue;
188 }
189
190 msListLabelString.clear();
191 if ( bExportTextNumberElement &&
192 xPropSetInfo->hasPropertyByName( "ListLabelString" ) )
193 {
194 xPropSet->getPropertyValue( "ListLabelString" ) >>= msListLabelString;
195 }
196
197 // paragraph's list level range is [0..9] representing list levels [1..10]
198 ++mnListLevel;
199 }
200 else
201 {
202 mnListLevel = 0;
203 }
204}
205
207{
208 bool bRet( true );
209 // Currently only the text documents support <ListId>.
210 if ( !rCmp.msListId.isEmpty() || !msListId.isEmpty() )
211 {
212 bRet = rCmp.msListId == msListId;
213 }
214 else
215 {
216 bRet = rCmp.msNumRulesName == msNumRulesName;
217 }
218
219 return bRet;
220}
221
222/* 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.
css::uno::Reference< css::container::XIndexReplace > mxNumRules
void Set(const css::uno::Reference< css::text::XTextContent > &rTextContent, bool bOutlineStyleAsNormalListStyle, const XMLTextListAutoStylePool &rListAutoPool, bool bExportTextNumberElement, bool bListIdIsDefault)
bool BelongsToSameList(const XMLTextNumRuleInfo &rCmp) const
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)