Line data Source code
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 : #include <rtl/ustring.hxx>
23 : #include <rtl/ustrbuf.hxx>
24 :
25 : #include <vector>
26 :
27 :
28 : #include <com/sun/star/lang/XServiceInfo.hpp>
29 : #include <com/sun/star/container/XIndexReplace.hpp>
30 :
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"
50 :
51 : using namespace ::com::sun::star;
52 : using namespace ::com::sun::star::text;
53 : using namespace ::com::sun::star::uno;
54 : using namespace ::std;
55 :
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;
63 :
64 1168 : void XMLTextParagraphExport::exportListAndSectionChange(
65 : Reference<XTextSection> & rPrevSection,
66 : const Reference<XTextContent> & rNextSectionContent,
67 : const XMLTextNumRuleInfo& rPrevRule,
68 : const XMLTextNumRuleInfo& rNextRule,
69 : bool bAutoStyles)
70 : {
71 1168 : Reference<XTextSection> xNextSection;
72 :
73 : // first: get current XTextSection
74 2336 : Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
75 1168 : if (xPropSet.is())
76 : {
77 1168 : if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextSection))
78 : {
79 72 : xPropSet->getPropertyValue(sTextSection) >>= xNextSection;
80 : }
81 : // else: no current section
82 : }
83 :
84 : exportListAndSectionChange(rPrevSection, xNextSection,
85 2336 : rPrevRule, rNextRule, bAutoStyles);
86 1168 : }
87 :
88 1333 : 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)
96 : {
97 1333 : Reference<XTextSection> xNextSection;
98 :
99 : // first: get current XTextSection
100 2666 : Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
101 1333 : if (xPropSet.is())
102 : {
103 1333 : if( !rPropSetHelper.checkedProperties() )
104 601 : rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
105 1333 : if( rPropSetHelper.hasProperty( nTextSectionId ))
106 : {
107 : xNextSection.set(rPropSetHelper.getValue( nTextSectionId , xPropSet,
108 932 : true ), uno::UNO_QUERY);
109 : }
110 : // else: no current section
111 : }
112 :
113 : exportListAndSectionChange(rPrevSection, xNextSection,
114 2666 : rPrevRule, rNextRule, bAutoStyles);
115 1333 : }
116 :
117 3102 : void XMLTextParagraphExport::exportListAndSectionChange(
118 : Reference<XTextSection> & rPrevSection,
119 : const Reference<XTextSection> & rNextSection,
120 : const XMLTextNumRuleInfo& rPrevRule,
121 : const XMLTextNumRuleInfo& rNextRule,
122 : bool bAutoStyles)
123 : {
124 : // old != new? -> maybe we have to start or end a new section
125 3102 : if (rPrevSection != rNextSection)
126 : {
127 : // a new section started, or an old one gets closed!
128 :
129 : // close old list
130 56 : XMLTextNumRuleInfo aEmptyNumRuleInfo;
131 56 : if ( !bAutoStyles )
132 56 : exportListChange(rPrevRule, aEmptyNumRuleInfo);
133 :
134 : // Build stacks of old and new sections
135 : // Sections on top of mute sections should not be on the stack
136 112 : vector< Reference<XTextSection> > aOldStack;
137 112 : Reference<XTextSection> aCurrent(rPrevSection);
138 150 : while(aCurrent.is())
139 : {
140 : // if we have a mute section, ignore all its children
141 : // (all previous ones)
142 38 : if (pSectionExport->IsMuteSection(aCurrent))
143 0 : aOldStack.clear();
144 :
145 38 : aOldStack.push_back(aCurrent);
146 38 : aCurrent.set(aCurrent->getParentSection());
147 : }
148 :
149 112 : vector< Reference<XTextSection> > aNewStack;
150 56 : aCurrent.set(rNextSection);
151 56 : bool bMute = false;
152 150 : while(aCurrent.is())
153 : {
154 : // if we have a mute section, ignore all its children
155 : // (all previous ones)
156 38 : if (pSectionExport->IsMuteSection(aCurrent))
157 : {
158 0 : aNewStack.clear();
159 0 : bMute = true;
160 : }
161 :
162 38 : aNewStack.push_back(aCurrent);
163 38 : aCurrent.set(aCurrent->getParentSection());
164 : }
165 :
166 : // compare the two stacks
167 : vector<Reference<XTextSection> > ::reverse_iterator aOld =
168 56 : aOldStack.rbegin();
169 : vector<Reference<XTextSection> > ::reverse_iterator aNew =
170 56 : aNewStack.rbegin();
171 : // compare bottom sections and skip equal section
172 340 : while ( (aOld != aOldStack.rend()) &&
173 258 : (aNew != aNewStack.rend()) &&
174 4 : (*aOld) == (*aNew) )
175 : {
176 0 : ++aOld;
177 0 : ++aNew;
178 : }
179 :
180 : // close all elements of aOld ...
181 : // (order: newest to oldest)
182 56 : if (aOld != aOldStack.rend())
183 : {
184 : vector<Reference<XTextSection> > ::iterator aOldForward(
185 30 : aOldStack.begin());
186 106 : while ((aOldForward != aOldStack.end()) &&
187 38 : (*aOldForward != *aOld))
188 : {
189 8 : if ( !bAutoStyles && (NULL != pRedlineExport) )
190 8 : pRedlineExport->ExportStartOrEndRedline(*aOldForward,
191 8 : false);
192 8 : pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
193 8 : ++aOldForward;
194 : }
195 30 : if (aOldForward != aOldStack.end())
196 : {
197 30 : if ( !bAutoStyles && (NULL != pRedlineExport) )
198 30 : pRedlineExport->ExportStartOrEndRedline(*aOldForward,
199 30 : false);
200 30 : pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
201 : }
202 : }
203 :
204 : // ...then open all of aNew
205 : // (order: oldest to newest)
206 150 : while (aNew != aNewStack.rend())
207 : {
208 38 : if ( !bAutoStyles && (NULL != pRedlineExport) )
209 38 : pRedlineExport->ExportStartOrEndRedline(*aNew, true);
210 38 : pSectionExport->ExportSectionStart(*aNew, bAutoStyles);
211 38 : ++aNew;
212 : }
213 :
214 : // start new list
215 56 : if ( !bAutoStyles && !bMute )
216 112 : exportListChange(aEmptyNumRuleInfo, rNextRule);
217 : }
218 : else
219 : {
220 : // list change, if sections have not changed
221 3046 : if ( !bAutoStyles )
222 1890 : exportListChange(rPrevRule, rNextRule);
223 : }
224 :
225 : // save old section (old numRule gets saved in calling method)
226 3102 : rPrevSection.set(rNextSection);
227 3102 : }
228 :
229 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|