LibreOffice Module xmloff (master) 1
txtsecte.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 <xmloff/txtparae.hxx>
22
23#include <vector>
24
25#include <com/sun/star/beans/XPropertySet.hpp>
26#include <com/sun/star/text/XTextSection.hpp>
28#include "XMLSectionExport.hxx"
29#include "XMLRedlineExport.hxx"
31
32using namespace ::com::sun::star;
33using namespace ::com::sun::star::text;
34using namespace ::com::sun::star::uno;
35
36using ::com::sun::star::beans::XPropertySet;
37
39 Reference<XTextSection> & rPrevSection,
40 const Reference<XTextContent> & rNextSectionContent,
41 const XMLTextNumRuleInfo& rPrevRule,
42 const XMLTextNumRuleInfo& rNextRule,
43 bool bAutoStyles)
44{
45 Reference<XTextSection> xNextSection;
46
47 // first: get current XTextSection
48 Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
49 if (xPropSet.is())
50 {
51 if (xPropSet->getPropertySetInfo()->hasPropertyByName(gsTextSection))
52 {
53 xPropSet->getPropertyValue(gsTextSection) >>= xNextSection;
54 }
55 // else: no current section
56 }
57
58 exportListAndSectionChange(rPrevSection, xNextSection,
59 rPrevRule, rNextRule, bAutoStyles);
60}
61
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)
70{
71 Reference<XTextSection> xNextSection;
72
73 // first: get current XTextSection
74 Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
75 if (xPropSet.is())
76 {
77 if( !rPropSetHelper.checkedProperties() )
78 rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
79 if( rPropSetHelper.hasProperty( nTextSectionId ))
80 {
81 xNextSection.set(rPropSetHelper.getValue( nTextSectionId , xPropSet,
82 true ), uno::UNO_QUERY);
83 }
84 // else: no current section
85 }
86
87 exportListAndSectionChange(rPrevSection, xNextSection,
88 rPrevRule, rNextRule, bAutoStyles);
89}
90
92 Reference<XTextSection> & rPrevSection,
93 const Reference<XTextSection> & rNextSection,
94 const XMLTextNumRuleInfo& rPrevRule,
95 const XMLTextNumRuleInfo& rNextRule,
96 bool bAutoStyles)
97{
98 // old != new? -> maybe we have to start or end a new section
99 if (rPrevSection != rNextSection)
100 {
101 // a new section started, or an old one gets closed!
102
103 // close old list
104 XMLTextNumRuleInfo aEmptyNumRuleInfo;
105 if ( !bAutoStyles )
106 exportListChange(rPrevRule, aEmptyNumRuleInfo);
107
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())
113 {
114 // if we have a mute section, ignore all its children
115 // (all previous ones)
116 if (m_pSectionExport->IsMuteSection(aCurrent))
117 aOldStack.clear();
118
119 aOldStack.push_back(aCurrent);
120 aCurrent.set(aCurrent->getParentSection());
121 }
122
123 std::vector< Reference<XTextSection> > aNewStack;
124 aCurrent.set(rNextSection);
125 bool bMute = false;
126 while(aCurrent.is())
127 {
128 // if we have a mute section, ignore all its children
129 // (all previous ones)
130 if (m_pSectionExport->IsMuteSection(aCurrent))
131 {
132 aNewStack.clear();
133 bMute = true;
134 }
135
136 aNewStack.push_back(aCurrent);
137 aCurrent.set(aCurrent->getParentSection());
138 }
139
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) )
149 {
150 ++aOld;
151 ++aNew;
152 }
153
154 // close all elements of aOld ...
155 // (order: newest to oldest)
156 if (aOld != aOldStack.rend())
157 {
158 std::vector<Reference<XTextSection> > ::iterator aOldForward(
159 aOldStack.begin());
160 while ((aOldForward != aOldStack.end()) &&
161 (*aOldForward != *aOld))
162 {
163 if ( !bAutoStyles && (nullptr != m_pRedlineExport) )
164 m_pRedlineExport->ExportStartOrEndRedline(*aOldForward,
165 false);
166 m_pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
167 ++aOldForward;
168 }
169 if (aOldForward != aOldStack.end())
170 {
171 if ( !bAutoStyles && (nullptr != m_pRedlineExport) )
172 m_pRedlineExport->ExportStartOrEndRedline(*aOldForward,
173 false);
174 m_pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
175 }
176 }
177
178 // ...then open all of aNew
179 // (order: oldest to newest)
180 while (aNew != aNewStack.rend())
181 {
182 if ( !bAutoStyles && (nullptr != m_pRedlineExport) )
183 m_pRedlineExport->ExportStartOrEndRedline(*aNew, true);
184 m_pSectionExport->ExportSectionStart(*aNew, bAutoStyles);
185 ++aNew;
186 }
187
188 // start new list
189 if ( !bAutoStyles && !bMute )
190 exportListChange(aEmptyNumRuleInfo, rNextRule);
191 }
192 else
193 {
194 // list change, if sections have not changed
195 if ( !bAutoStyles )
196 exportListChange(rPrevRule, rNextRule);
197 }
198
199 // save old section (old numRule gets saved in calling method)
200 rPrevSection.set(rNextSection);
201}
202
203/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
The MultiPropertySetHelper performs the following functions:
void hasProperties(const css::uno::Reference< css::beans::XPropertySetInfo > &)
Call hasPropertiesByName for the provided XPropertySetInfo and build list of allowed properties.
const css::uno::Any & getValue(sal_Int16 nIndex)
Get a value from the values array.
bool hasProperty(sal_Int16 nIndex)
Find out if this property is supported.
bool checkedProperties()
Return whether hasProperties was called (i.e.
information about list and list style for a certain paragraph
std::unique_ptr< XMLRedlineExport > m_pRedlineExport
may be NULL (if no redlines should be exported; e.g. in block mode)
Definition: txtparae.hxx:101
std::unique_ptr< XMLSectionExport > m_pSectionExport
Definition: txtparae.hxx:97
void exportListAndSectionChange(css::uno::Reference< css::text::XTextSection > &rOldSection, const css::uno::Reference< css::text::XTextSection > &rNewSection, const XMLTextNumRuleInfo &rOldList, const XMLTextNumRuleInfo &rNewList, bool bAutoStyles)
check if current section or current list has changed; calls exportListChange as appropriate
static constexpr OUStringLiteral gsTextSection
Definition: txtparae.hxx:160
void exportListChange(const XMLTextNumRuleInfo &rPrvInfo, const XMLTextNumRuleInfo &rNextInfo)
Definition: txtparae.cxx:993