merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / text / txtsecte.cxx
blobbd05aa4ba2aca6414e22266c29fceb53b88e2ca4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: txtsecte.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #ifndef _XMLOFF_TXTPARAE_HXX
35 #include <xmloff/txtparae.hxx>
36 #endif
37 #include <tools/debug.hxx>
38 #include <rtl/ustring.hxx>
39 #include <rtl/ustrbuf.hxx>
41 #include <vector>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/container/XIndexReplace.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/beans/PropertyValue.hpp>
49 #include <com/sun/star/beans/PropertyValues.hpp>
50 #include <com/sun/star/beans/PropertyState.hpp>
51 #include <com/sun/star/text/XText.hpp>
52 #include <com/sun/star/text/XTextSection.hpp>
53 #include <com/sun/star/text/SectionFileLink.hpp>
54 #include <com/sun/star/container/XNamed.hpp>
55 #include <com/sun/star/text/XDocumentIndex.hpp>
56 #include "xmlnmspe.hxx"
57 #include <xmloff/families.hxx>
58 #include <xmloff/xmluconv.hxx>
59 #include <xmloff/nmspmap.hxx>
60 #include <xmloff/xmlexp.hxx>
61 #include <xmloff/xmltkmap.hxx>
62 #include "XMLTextNumRuleInfo.hxx"
63 #include "XMLSectionExport.hxx"
64 #include "XMLRedlineExport.hxx"
65 #ifndef _XMLOFF_MULTIPROPERTYSETHELPER_HXX
66 #include "MultiPropertySetHelper.hxx"
67 #endif
69 using namespace ::com::sun::star;
70 using namespace ::com::sun::star::text;
71 using namespace ::com::sun::star::uno;
72 using namespace ::std;
74 using ::rtl::OUString;
75 using ::rtl::OUStringBuffer;
76 using ::com::sun::star::beans::XPropertySet;
77 using ::com::sun::star::beans::PropertyValue;
78 using ::com::sun::star::beans::PropertyValues;
79 using ::com::sun::star::beans::PropertyState;
80 using ::com::sun::star::container::XIndexReplace;
81 using ::com::sun::star::container::XNamed;
82 using ::com::sun::star::lang::XServiceInfo;
84 Reference<XText> lcl_findXText(const Reference<XTextSection>& rSect)
86 Reference<XText> xText;
88 Reference<XTextContent> xTextContent(rSect, UNO_QUERY);
89 if (xTextContent.is())
91 xText.set(xTextContent->getAnchor()->getText());
94 return xText;
97 void XMLTextParagraphExport::exportListAndSectionChange(
98 Reference<XTextSection> & rPrevSection,
99 const Reference<XTextContent> & rNextSectionContent,
100 const XMLTextNumRuleInfo& rPrevRule,
101 const XMLTextNumRuleInfo& rNextRule,
102 sal_Bool bAutoStyles)
104 Reference<XTextSection> xNextSection;
106 // first: get current XTextSection
107 Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
108 if (xPropSet.is())
110 if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextSection))
112 xPropSet->getPropertyValue(sTextSection) >>= xNextSection;
114 // else: no current section
117 exportListAndSectionChange(rPrevSection, xNextSection,
118 rPrevRule, rNextRule, bAutoStyles);
121 void XMLTextParagraphExport::exportListAndSectionChange(
122 Reference<XTextSection> & rPrevSection,
123 MultiPropertySetHelper& rPropSetHelper,
124 sal_Int16 nTextSectionId,
125 const Reference<XTextContent> & rNextSectionContent,
126 const XMLTextNumRuleInfo& rPrevRule,
127 const XMLTextNumRuleInfo& rNextRule,
128 sal_Bool bAutoStyles)
130 Reference<XTextSection> xNextSection;
132 // first: get current XTextSection
133 Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
134 if (xPropSet.is())
136 if( !rPropSetHelper.checkedProperties() )
137 rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
138 if( rPropSetHelper.hasProperty( nTextSectionId ))
140 xNextSection.set(rPropSetHelper.getValue( nTextSectionId , xPropSet,
141 sal_True ), uno::UNO_QUERY);
143 // else: no current section
146 exportListAndSectionChange(rPrevSection, xNextSection,
147 rPrevRule, rNextRule, bAutoStyles);
150 void XMLTextParagraphExport::exportListAndSectionChange(
151 Reference<XTextSection> & rPrevSection,
152 const Reference<XTextSection> & rNextSection,
153 const XMLTextNumRuleInfo& rPrevRule,
154 const XMLTextNumRuleInfo& rNextRule,
155 sal_Bool bAutoStyles)
157 // old != new? -> maybe we have to start or end a new section
158 if (rPrevSection != rNextSection)
160 // a new section started, or an old one gets closed!
162 // close old list
163 XMLTextNumRuleInfo aEmptyNumRuleInfo;
164 if ( !bAutoStyles )
165 exportListChange(rPrevRule, aEmptyNumRuleInfo);
167 // Build stacks of old and new sections
168 // Sections on top of mute sections should not be on the stack
169 vector< Reference<XTextSection> > aOldStack;
170 Reference<XTextSection> aCurrent(rPrevSection);
171 while(aCurrent.is())
173 // if we have a mute section, ignore all its children
174 // (all previous ones)
175 if (pSectionExport->IsMuteSection(aCurrent))
176 aOldStack.clear();
178 aOldStack.push_back(aCurrent);
179 aCurrent.set(aCurrent->getParentSection());
182 vector< Reference<XTextSection> > aNewStack;
183 aCurrent.set(rNextSection);
184 sal_Bool bMute = sal_False;
185 while(aCurrent.is())
187 // if we have a mute section, ignore all its children
188 // (all previous ones)
189 if (pSectionExport->IsMuteSection(aCurrent))
191 aNewStack.clear();
192 bMute = sal_True;
195 aNewStack.push_back(aCurrent);
196 aCurrent.set(aCurrent->getParentSection());
199 // compare the two stacks
200 vector<Reference<XTextSection> > ::reverse_iterator aOld =
201 aOldStack.rbegin();
202 vector<Reference<XTextSection> > ::reverse_iterator aNew =
203 aNewStack.rbegin();
204 // compare bottom sections and skip equal section
205 while ( (aOld != aOldStack.rend()) &&
206 (aNew != aNewStack.rend()) &&
207 (*aOld) == (*aNew) )
209 ++aOld;
210 ++aNew;
213 // close all elements of aOld ...
214 // (order: newest to oldest)
215 if (aOld != aOldStack.rend())
217 vector<Reference<XTextSection> > ::iterator aOldForward(
218 aOldStack.begin());
219 while ((aOldForward != aOldStack.end()) &&
220 (*aOldForward != *aOld))
222 if ( !bAutoStyles && (NULL != pRedlineExport) )
223 pRedlineExport->ExportStartOrEndRedline(*aOldForward,
224 sal_False);
225 pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
226 ++aOldForward;
228 if (aOldForward != aOldStack.end())
230 if ( !bAutoStyles && (NULL != pRedlineExport) )
231 pRedlineExport->ExportStartOrEndRedline(*aOldForward,
232 sal_False);
233 pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
237 // ...then open all of aNew
238 // (order: oldest to newest)
239 while (aNew != aNewStack.rend())
241 if ( !bAutoStyles && (NULL != pRedlineExport) )
242 pRedlineExport->ExportStartOrEndRedline(*aNew, sal_True);
243 pSectionExport->ExportSectionStart(*aNew, bAutoStyles);
244 ++aNew;
247 // start new list
248 if ( !bAutoStyles && !bMute )
249 exportListChange(aEmptyNumRuleInfo, rNextRule);
251 else
253 // list change, if sections have not changed
254 if ( !bAutoStyles )
255 exportListChange(rPrevRule, rNextRule);
258 // save old section (old numRule gets saved in calling method)
259 rPrevSection.set(rNextSection);