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