1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
,
45 Reference
<XTextSection
> xNextSection
;
47 // first: get current XTextSection
48 Reference
<XPropertySet
> xPropSet(rNextSectionContent
, UNO_QUERY
);
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
,
71 Reference
<XTextSection
> xNextSection
;
73 // first: get current XTextSection
74 Reference
<XPropertySet
> xPropSet(rNextSectionContent
, UNO_QUERY
);
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
,
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!
104 XMLTextNumRuleInfo aEmptyNumRuleInfo
;
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
);
114 // if we have a mute section, ignore all its children
115 // (all previous ones)
116 if (m_pSectionExport
->IsMuteSection(aCurrent
))
119 aOldStack
.push_back(aCurrent
);
120 aCurrent
.set(aCurrent
->getParentSection());
123 std::vector
< Reference
<XTextSection
> > aNewStack
;
124 aCurrent
.set(rNextSection
);
128 // if we have a mute section, ignore all its children
129 // (all previous ones)
130 if (m_pSectionExport
->IsMuteSection(aCurrent
))
136 aNewStack
.push_back(aCurrent
);
137 aCurrent
.set(aCurrent
->getParentSection());
140 // compare the two stacks
141 std::vector
<Reference
<XTextSection
> > ::reverse_iterator aOld
=
143 std::vector
<Reference
<XTextSection
> > ::reverse_iterator aNew
=
145 // compare bottom sections and skip equal section
146 while ( (aOld
!= aOldStack
.rend()) &&
147 (aNew
!= aNewStack
.rend()) &&
154 // close all elements of aOld ...
155 // (order: newest to oldest)
156 if (aOld
!= aOldStack
.rend())
158 std::vector
<Reference
<XTextSection
> > ::iterator
aOldForward(
160 while ((aOldForward
!= aOldStack
.end()) &&
161 (*aOldForward
!= *aOld
))
163 if ( !bAutoStyles
&& (nullptr != m_pRedlineExport
) )
164 m_pRedlineExport
->ExportStartOrEndRedline(*aOldForward
,
166 m_pSectionExport
->ExportSectionEnd(*aOldForward
, bAutoStyles
);
169 if (aOldForward
!= aOldStack
.end())
171 if ( !bAutoStyles
&& (nullptr != m_pRedlineExport
) )
172 m_pRedlineExport
->ExportStartOrEndRedline(*aOldForward
,
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
);
189 if ( !bAutoStyles
&& !bMute
)
190 exportListChange(aEmptyNumRuleInfo
, rNextRule
);
194 // list change, if sections have not changed
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: */