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 1524 : 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 1524 : Reference<XTextSection> xNextSection;
72 :
73 : // first: get current XTextSection
74 3048 : Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
75 1524 : if (xPropSet.is())
76 : {
77 1524 : if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextSection))
78 : {
79 32 : xPropSet->getPropertyValue(sTextSection) >>= xNextSection;
80 : }
81 : // else: no current section
82 : }
83 :
84 : exportListAndSectionChange(rPrevSection, xNextSection,
85 3048 : rPrevRule, rNextRule, bAutoStyles);
86 1524 : }
87 :
88 812 : 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 812 : Reference<XTextSection> xNextSection;
98 :
99 : // first: get current XTextSection
100 1624 : Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
101 812 : if (xPropSet.is())
102 : {
103 812 : if( !rPropSetHelper.checkedProperties() )
104 478 : rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
105 812 : if( rPropSetHelper.hasProperty( nTextSectionId ))
106 : {
107 : xNextSection.set(rPropSetHelper.getValue( nTextSectionId , xPropSet,
108 384 : true ), uno::UNO_QUERY);
109 : }
110 : // else: no current section
111 : }
112 :
113 : exportListAndSectionChange(rPrevSection, xNextSection,
114 1624 : rPrevRule, rNextRule, bAutoStyles);
115 812 : }
116 :
117 2814 : 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 2814 : if (rPrevSection != rNextSection)
126 : {
127 : // a new section started, or an old one gets closed!
128 :
129 : // close old list
130 64 : XMLTextNumRuleInfo aEmptyNumRuleInfo;
131 64 : if ( !bAutoStyles )
132 64 : 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 128 : vector< Reference<XTextSection> > aOldStack;
137 128 : Reference<XTextSection> aCurrent(rPrevSection);
138 178 : while(aCurrent.is())
139 : {
140 : // if we have a mute section, ignore all its children
141 : // (all previous ones)
142 50 : if (pSectionExport->IsMuteSection(aCurrent))
143 0 : aOldStack.clear();
144 :
145 50 : aOldStack.push_back(aCurrent);
146 50 : aCurrent.set(aCurrent->getParentSection());
147 : }
148 :
149 128 : vector< Reference<XTextSection> > aNewStack;
150 64 : aCurrent.set(rNextSection);
151 64 : bool bMute = false;
152 178 : while(aCurrent.is())
153 : {
154 : // if we have a mute section, ignore all its children
155 : // (all previous ones)
156 50 : if (pSectionExport->IsMuteSection(aCurrent))
157 : {
158 0 : aNewStack.clear();
159 0 : bMute = true;
160 : }
161 :
162 50 : aNewStack.push_back(aCurrent);
163 50 : aCurrent.set(aCurrent->getParentSection());
164 : }
165 :
166 : // compare the two stacks
167 : vector<Reference<XTextSection> > ::reverse_iterator aOld =
168 64 : aOldStack.rbegin();
169 : vector<Reference<XTextSection> > ::reverse_iterator aNew =
170 64 : aNewStack.rbegin();
171 : // compare bottom sections and skip equal section
172 388 : while ( (aOld != aOldStack.rend()) &&
173 294 : (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 64 : if (aOld != aOldStack.rend())
183 : {
184 : vector<Reference<XTextSection> > ::iterator aOldForward(
185 34 : aOldStack.begin());
186 134 : while ((aOldForward != aOldStack.end()) &&
187 50 : (*aOldForward != *aOld))
188 : {
189 16 : if ( !bAutoStyles && (NULL != pRedlineExport) )
190 16 : pRedlineExport->ExportStartOrEndRedline(*aOldForward,
191 16 : false);
192 16 : pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
193 16 : ++aOldForward;
194 : }
195 34 : if (aOldForward != aOldStack.end())
196 : {
197 34 : if ( !bAutoStyles && (NULL != pRedlineExport) )
198 34 : pRedlineExport->ExportStartOrEndRedline(*aOldForward,
199 34 : false);
200 34 : pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
201 : }
202 : }
203 :
204 : // ...then open all of aNew
205 : // (order: oldest to newest)
206 178 : while (aNew != aNewStack.rend())
207 : {
208 50 : if ( !bAutoStyles && (NULL != pRedlineExport) )
209 50 : pRedlineExport->ExportStartOrEndRedline(*aNew, true);
210 50 : pSectionExport->ExportSectionStart(*aNew, bAutoStyles);
211 50 : ++aNew;
212 : }
213 :
214 : // start new list
215 64 : if ( !bAutoStyles && !bMute )
216 128 : exportListChange(aEmptyNumRuleInfo, rNextRule);
217 : }
218 : else
219 : {
220 : // list change, if sections have not changed
221 2750 : if ( !bAutoStyles )
222 1228 : exportListChange(rPrevRule, rNextRule);
223 : }
224 :
225 : // save old section (old numRule gets saved in calling method)
226 2814 : rPrevSection.set(rNextSection);
227 2814 : }
228 :
229 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|