tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / xmloff / source / text / txtsecte.cxx
blob14589b961d817db0df90f9965aff7212c9cada5c
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>
23 #include <vector>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/text/XTextSection.hpp>
27 #include "XMLTextNumRuleInfo.hxx"
28 #include "XMLSectionExport.hxx"
29 #include "XMLRedlineExport.hxx"
30 #include <MultiPropertySetHelper.hxx>
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::text;
34 using namespace ::com::sun::star::uno;
36 using ::com::sun::star::beans::XPropertySet;
38 void XMLTextParagraphExport::exportListAndSectionChange(
39 Reference<XTextSection> & rPrevSection,
40 const Reference<XTextContent> & rNextSectionContent,
41 const XMLTextNumRuleInfo& rPrevRule,
42 const XMLTextNumRuleInfo& rNextRule,
43 bool bAutoStyles)
45 Reference<XTextSection> xNextSection;
47 // first: get current XTextSection
48 Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
49 if (xPropSet.is())
51 if (xPropSet->getPropertySetInfo()->hasPropertyByName(gsTextSection))
53 xPropSet->getPropertyValue(gsTextSection) >>= xNextSection;
55 // else: no current section
58 exportListAndSectionChange(rPrevSection, xNextSection,
59 rPrevRule, rNextRule, bAutoStyles);
62 void XMLTextParagraphExport::exportListAndSectionChange(
63 Reference<XTextSection> & rPrevSection,
64 MultiPropertySetHelper& rPropSetHelper,
65 sal_Int16 nTextSectionId,
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( !rPropSetHelper.checkedProperties() )
78 rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
79 if( rPropSetHelper.hasProperty( nTextSectionId ))
81 xNextSection.set(rPropSetHelper.getValue( nTextSectionId , xPropSet,
82 true ), uno::UNO_QUERY);
84 // else: no current section
87 exportListAndSectionChange(rPrevSection, xNextSection,
88 rPrevRule, rNextRule, bAutoStyles);
91 void XMLTextParagraphExport::exportListAndSectionChange(
92 Reference<XTextSection> & rPrevSection,
93 const Reference<XTextSection> & rNextSection,
94 const XMLTextNumRuleInfo& rPrevRule,
95 const XMLTextNumRuleInfo& rNextRule,
96 bool bAutoStyles)
98 // old != new? -> maybe we have to start or end a new section
99 if (rPrevSection != rNextSection)
101 // a new section started, or an old one gets closed!
103 // close old list
104 XMLTextNumRuleInfo aEmptyNumRuleInfo;
105 if ( !bAutoStyles )
106 exportListChange(rPrevRule, aEmptyNumRuleInfo);
108 // Build stacks of old and new sections
109 // Sections on top of mute sections should not be on the stack
110 std::vector< Reference<XTextSection> > aOldStack;
111 Reference<XTextSection> aCurrent(rPrevSection);
112 while(aCurrent.is())
114 // if we have a mute section, ignore all its children
115 // (all previous ones)
116 if (m_pSectionExport->IsMuteSection(aCurrent))
117 aOldStack.clear();
119 aOldStack.push_back(aCurrent);
120 aCurrent.set(aCurrent->getParentSection());
123 std::vector< Reference<XTextSection> > aNewStack;
124 aCurrent.set(rNextSection);
125 bool bMute = false;
126 while(aCurrent.is())
128 // if we have a mute section, ignore all its children
129 // (all previous ones)
130 if (m_pSectionExport->IsMuteSection(aCurrent))
132 aNewStack.clear();
133 bMute = true;
136 aNewStack.push_back(aCurrent);
137 aCurrent.set(aCurrent->getParentSection());
140 // compare the two stacks
141 std::vector<Reference<XTextSection> > ::reverse_iterator aOld =
142 aOldStack.rbegin();
143 std::vector<Reference<XTextSection> > ::reverse_iterator aNew =
144 aNewStack.rbegin();
145 // compare bottom sections and skip equal section
146 while ( (aOld != aOldStack.rend()) &&
147 (aNew != aNewStack.rend()) &&
148 (*aOld) == (*aNew) )
150 ++aOld;
151 ++aNew;
154 // close all elements of aOld ...
155 // (order: newest to oldest)
156 if (aOld != aOldStack.rend())
158 std::vector<Reference<XTextSection> > ::iterator aOldForward(
159 aOldStack.begin());
160 while ((aOldForward != aOldStack.end()) &&
161 (*aOldForward != *aOld))
163 if ( !bAutoStyles && (nullptr != m_pRedlineExport) )
164 m_pRedlineExport->ExportStartOrEndRedline(*aOldForward,
165 false);
166 m_pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
167 ++aOldForward;
169 if (aOldForward != aOldStack.end())
171 if ( !bAutoStyles && (nullptr != m_pRedlineExport) )
172 m_pRedlineExport->ExportStartOrEndRedline(*aOldForward,
173 false);
174 m_pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
178 // ...then open all of aNew
179 // (order: oldest to newest)
180 while (aNew != aNewStack.rend())
182 if ( !bAutoStyles && (nullptr != m_pRedlineExport) )
183 m_pRedlineExport->ExportStartOrEndRedline(*aNew, true);
184 m_pSectionExport->ExportSectionStart(*aNew, bAutoStyles);
185 ++aNew;
188 // start new list
189 if ( !bAutoStyles && !bMute )
190 exportListChange(aEmptyNumRuleInfo, rNextRule);
192 else
194 // list change, if sections have not changed
195 if ( !bAutoStyles )
196 exportListChange(rPrevRule, rNextRule);
199 // save old section (old numRule gets saved in calling method)
200 rPrevSection.set(rNextSection);
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */