bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / txtsecte.cxx
blobec59681eca214d31d3f2c375cbed10371c1451d5
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 <xmloff/txtparae.hxx>
22 #include <rtl/ustring.hxx>
23 #include <rtl/ustrbuf.hxx>
25 #include <vector>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/container/XIndexReplace.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <com/sun/star/beans/PropertyValues.hpp>
34 #include <com/sun/star/beans/PropertyState.hpp>
35 #include <com/sun/star/text/XText.hpp>
36 #include <com/sun/star/text/XTextSection.hpp>
37 #include <com/sun/star/text/SectionFileLink.hpp>
38 #include <com/sun/star/container/XNamed.hpp>
39 #include <com/sun/star/text/XDocumentIndex.hpp>
40 #include <xmloff/xmlnmspe.hxx>
41 #include <xmloff/families.hxx>
42 #include <xmloff/xmluconv.hxx>
43 #include <xmloff/nmspmap.hxx>
44 #include <xmloff/xmlexp.hxx>
45 #include <xmloff/xmltkmap.hxx>
46 #include "XMLTextNumRuleInfo.hxx"
47 #include "XMLSectionExport.hxx"
48 #include "XMLRedlineExport.hxx"
49 #include "MultiPropertySetHelper.hxx"
51 using namespace ::com::sun::star;
52 using namespace ::com::sun::star::text;
53 using namespace ::com::sun::star::uno;
54 using namespace ::std;
56 using ::com::sun::star::beans::XPropertySet;
57 using ::com::sun::star::beans::PropertyValue;
58 using ::com::sun::star::beans::PropertyValues;
59 using ::com::sun::star::beans::PropertyState;
60 using ::com::sun::star::container::XIndexReplace;
61 using ::com::sun::star::container::XNamed;
62 using ::com::sun::star::lang::XServiceInfo;
64 void XMLTextParagraphExport::exportListAndSectionChange(
65 Reference<XTextSection> & rPrevSection,
66 const Reference<XTextContent> & rNextSectionContent,
67 const XMLTextNumRuleInfo& rPrevRule,
68 const XMLTextNumRuleInfo& rNextRule,
69 bool bAutoStyles)
71 Reference<XTextSection> xNextSection;
73 // first: get current XTextSection
74 Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
75 if (xPropSet.is())
77 if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextSection))
79 xPropSet->getPropertyValue(sTextSection) >>= xNextSection;
81 // else: no current section
84 exportListAndSectionChange(rPrevSection, xNextSection,
85 rPrevRule, rNextRule, bAutoStyles);
88 void XMLTextParagraphExport::exportListAndSectionChange(
89 Reference<XTextSection> & rPrevSection,
90 MultiPropertySetHelper& rPropSetHelper,
91 sal_Int16 nTextSectionId,
92 const Reference<XTextContent> & rNextSectionContent,
93 const XMLTextNumRuleInfo& rPrevRule,
94 const XMLTextNumRuleInfo& rNextRule,
95 bool bAutoStyles)
97 Reference<XTextSection> xNextSection;
99 // first: get current XTextSection
100 Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
101 if (xPropSet.is())
103 if( !rPropSetHelper.checkedProperties() )
104 rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
105 if( rPropSetHelper.hasProperty( nTextSectionId ))
107 xNextSection.set(rPropSetHelper.getValue( nTextSectionId , xPropSet,
108 true ), uno::UNO_QUERY);
110 // else: no current section
113 exportListAndSectionChange(rPrevSection, xNextSection,
114 rPrevRule, rNextRule, bAutoStyles);
117 void XMLTextParagraphExport::exportListAndSectionChange(
118 Reference<XTextSection> & rPrevSection,
119 const Reference<XTextSection> & rNextSection,
120 const XMLTextNumRuleInfo& rPrevRule,
121 const XMLTextNumRuleInfo& rNextRule,
122 bool bAutoStyles)
124 // old != new? -> maybe we have to start or end a new section
125 if (rPrevSection != rNextSection)
127 // a new section started, or an old one gets closed!
129 // close old list
130 XMLTextNumRuleInfo aEmptyNumRuleInfo;
131 if ( !bAutoStyles )
132 exportListChange(rPrevRule, aEmptyNumRuleInfo);
134 // Build stacks of old and new sections
135 // Sections on top of mute sections should not be on the stack
136 vector< Reference<XTextSection> > aOldStack;
137 Reference<XTextSection> aCurrent(rPrevSection);
138 while(aCurrent.is())
140 // if we have a mute section, ignore all its children
141 // (all previous ones)
142 if (pSectionExport->IsMuteSection(aCurrent))
143 aOldStack.clear();
145 aOldStack.push_back(aCurrent);
146 aCurrent.set(aCurrent->getParentSection());
149 vector< Reference<XTextSection> > aNewStack;
150 aCurrent.set(rNextSection);
151 bool bMute = false;
152 while(aCurrent.is())
154 // if we have a mute section, ignore all its children
155 // (all previous ones)
156 if (pSectionExport->IsMuteSection(aCurrent))
158 aNewStack.clear();
159 bMute = true;
162 aNewStack.push_back(aCurrent);
163 aCurrent.set(aCurrent->getParentSection());
166 // compare the two stacks
167 vector<Reference<XTextSection> > ::reverse_iterator aOld =
168 aOldStack.rbegin();
169 vector<Reference<XTextSection> > ::reverse_iterator aNew =
170 aNewStack.rbegin();
171 // compare bottom sections and skip equal section
172 while ( (aOld != aOldStack.rend()) &&
173 (aNew != aNewStack.rend()) &&
174 (*aOld) == (*aNew) )
176 ++aOld;
177 ++aNew;
180 // close all elements of aOld ...
181 // (order: newest to oldest)
182 if (aOld != aOldStack.rend())
184 vector<Reference<XTextSection> > ::iterator aOldForward(
185 aOldStack.begin());
186 while ((aOldForward != aOldStack.end()) &&
187 (*aOldForward != *aOld))
189 if ( !bAutoStyles && (NULL != pRedlineExport) )
190 pRedlineExport->ExportStartOrEndRedline(*aOldForward,
191 false);
192 pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
193 ++aOldForward;
195 if (aOldForward != aOldStack.end())
197 if ( !bAutoStyles && (NULL != pRedlineExport) )
198 pRedlineExport->ExportStartOrEndRedline(*aOldForward,
199 false);
200 pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
204 // ...then open all of aNew
205 // (order: oldest to newest)
206 while (aNew != aNewStack.rend())
208 if ( !bAutoStyles && (NULL != pRedlineExport) )
209 pRedlineExport->ExportStartOrEndRedline(*aNew, true);
210 pSectionExport->ExportSectionStart(*aNew, bAutoStyles);
211 ++aNew;
214 // start new list
215 if ( !bAutoStyles && !bMute )
216 exportListChange(aEmptyNumRuleInfo, rNextRule);
218 else
220 // list change, if sections have not changed
221 if ( !bAutoStyles )
222 exportListChange(rPrevRule, rNextRule);
225 // save old section (old numRule gets saved in calling method)
226 rPrevSection.set(rNextSection);
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */